用来记录以供日后查阅
创建numpy的方法
a=np.array([1,2,3])
获取numpy的维度
print(a.size)
np.arange()函数返回一个有终点和起点的固定步长的排列
#一个参数 默认起点0,步长为1 输出:[0 1 2]
a = np.arange(3)
#两个参数 默认步长为1 输出[3 4 5 6 7 8]
a = np.arange(3,9)
#三个参数 起点为0,终点为4,步长为0.1 输出[ 0. 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1. 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2. 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9]
a = np.arange(0, 3, 0.1)
numpy.linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None)
>>> np.linspace(2.0, 3.0, num=5)
array([ 2. , 2.25, 2.5 , 2.75, 3. ])
>>> np.linspace(2.0, 3.0, num=5, endpoint=False)
array([ 2. , 2.2, 2.4, 2.6, 2.8])
>>> np.linspace(2.0, 3.0, num=5, retstep=True)
(array([ 2. , 2.25, 2.5 , 2.75, 3. ]), 0.25)
numpy.meshgrid()
功能:快速画网格
参考:https://blog.csdn.net/lllxxq141592654/article/details/81532855
import numpy as np
import matplotlib.pyplot as plt
xx = np.array([[0, 1, 2], [0, 1, 2]])
yy = np.array([[0, 0, 0], [1, 1, 1]])
xx=np.array([0,1,2,0,1,2])
yy=np.array([0,0,0,1,1,1])
x=np.array([0,1,2])
y=np.array([0,1])
xx,yy=np.meshgrid(x,y)
print(xx)
print(yy)
x = np.linspace(0,1000,20)
y = np.linspace(0,500,20)
xx,yy=np.meshgrid(x,y)
plt.plot(xx, yy,
color='red',
marker='.',
linestyle='')
#plt.grid(True)
plt.show()
用相同方式打乱两个numpy
state = np.random.get_state()
np.random.shuffle(testx)
np.random.set_state(state)
np.random.shuffle(testy)