About taking random numbers, random matrices, random arrays, etc. in python

1. x[:,m:n], that is, take the mth to n-1th column data of all data sets

2. x[:-n] except the last n numbers, get all other data

      x[-n:] only get the last n data 

train_data = all_data[:-12]#除了最后12个数据,其他全取
test_data = all_data[-12:]#取最后12个数据
3、range(10)相当于range(0,10)
>>>range(10)        # 从 0 开始到 10
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> range(1, 11)     # 从 1 开始到 11
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
>>> range(0, 30, 5)  # 步长为 5
[0, 5, 10, 15, 20, 25]

4. The arange function of numpy commonly used functions

np.arange([start, ]stop, [step, ]dtype=None)

import numpy as np
nd1 = np.arange(5)#[0, 1, 2, 3, 4]
nd2 = np.arange(1,5)#[1, 2, 3, 4]
nd3 = np.arange(1,5,2)#[1 3]

nd2.reshape(2,2)#[[1, 2], [3, 4]]
np.reshape(nd2,(2,2))#同上

reshape, reshape the array.

The number of reshaped elements cannot be greater than the original number of elements, otherwise an error will be reported.
For example, nd2 generates four elements. If you want to reshape (2,3) to be six elements, you will get an error.

Guess you like

Origin blog.csdn.net/ch206265/article/details/106940373