# 菜鸟 深 学 的 逆袭 旅行 # day10 + strip function analysis

1. Reading of files in python ( open/文件操作):

f=open('/tmp/hello','w')
#open(路径+文件名,读写模式)

How to open the file:
handle = open (file_name, access_mode = 'r') The
file_name variable contains the string name of the file we want to open, 'r' in access_mode means read, 'w' means write, 'a' means Add, etc. If access_mode is not provided, the default is 'r'.
If open () succeeds, a file object handle will be returned.

	我们谈到"文本处理"时,我们通常指处理的内容。python将文本文件的内容读入可以操作的字符串变量非常容易。文件对象提供了三个'读'方法:.read()、.readline()、.readlines()。每种方法可以接受一个变量以限制每次读取的数据量,但它们通常不使用变量。.read()每次读取整个文件,它通常用域将文件内容放到一个字符串变量中。然而,.read()生成文件内容最直接的字符串表示,但对于连续的面向行的处理,它却是不必要的,并且如果文件大于可用内存,则不可能实现这种处理。
	.readline() 和 .readlines() 非常相似。它们都在类似于以下的结构中使用:
fh = open('c:\\autoexec.bat')
for  line in  fh.readlines(): 
	print(line)

The difference between .readline () and .readlines () is that the latter reads the entire file at once, just like .read (). .readlines () automatically parses the contents of the file into a list of lines, which can be processed by Python's for ... in ... structure. On the other hand, .readline () only reads one line at a time, which is usually much slower than .readlines (). .Readline () should only be used when there is not enough memory to read the entire file at once.

The original text is reproduced from: https://www.cnblogs.com/ghsme/p/3281169.html

2. # numpy.random.choice (a, size = None, replace = True, p = None)
# Randomly extract numbers from a (as long as it is an ndarray, but must be one-dimensional), and form a specified size ( size) array
#replace: True means the same number can be taken, False means the same number cannot be taken
# Array p: corresponds to array a, means the probability of taking each element in array a, the default is the probability of selecting each element the same.
It is indeed selected according to probability.
Original reference:
https://blog.csdn.net/ImwaterP/article/details/96282230

3. The python strip()方法
python strip () function is used to remove the specified characters (default space or newline) or character sequence at the beginning and end of the string.
Note: This method can only delete the characters at the beginning or the end, not the characters in the middle.

str1 = '00000003210Runoob01230000000'
print(str1.strip('0')) # 去除首尾字符 0

str2 = '   Runoob      '
print(str2.strip())  # 去除首尾空格

# ---- outputs ----
# 3210Runoob0123
# Runoob

4. np.random.shuffle(X)Usage
Modify the sequence (list) X on the spot and change its content. (Similar shuffle, shuffle order)

x = np.arange(10)
print(x)
np.random.shuffle(x)
print(x)

# ---- output ----
# [0 1 2 3 4 5 6 7 8 9]
# [2 1 8 4 3 5 0 9 7 6]

5. Callback function The callback
function is a set of functions that are called at a specific stage of training. You can use the callback function to observe the internal state and statistics of the network during the training process. By passing a list of callback functions to the model's .fit (), the functions in the function set can be called at a given training stage.

6.LSTM layer

keras.layers.recurrent.LSTM(units, activation='tanh', recurrent_activation='hard_sigmoid', use_bias=True, kernel_initializer='glorot_uniform', recurrent_initializer='orthogonal', bias_initializer='zeros', unit_forget_bias=True, kernel_regularizer=None, recurrent_regularizer=None, bias_regularizer=None, activity_regularizer=None, kernel_constraint=None, recurrent_constraint=None, bias_constraint=None, dropout=0.0, recurrent_dropout=0.0)

7. LambdaLayer

x = Lambda(lambda x:X[:,t,:])(X)
#相当于对后面的张量X执行函数,并返回之后的张量。
#eg:model.add(Lambda(lambda x: x ** 2))

8. LSTM layer return_state:
return_state: default false. When true, return the output hidden state and input unit state of the last step of the last layer.

Published 31 original articles · praised 0 · visits 674

Guess you like

Origin blog.csdn.net/ballzy/article/details/105635774