
一、基础使用
import numpy as np
#长度是10的全0的数组
a = np.zeros(10)
print(a,a.dtype)
b = np.zeros(10,dtype = "int")
print(b,b.dtype)
#长度为10的全1的数组
c = np.ones(10)
print(c)
d = np.empty(100)
print(d)

二、range
1、生成0-100
c = np.arange(100)
print(c)

2、生成2-10
d = np.arange(2,10)
print(d)

3、步长
#生成2到10数组,步长3
d = np.arange(2,10,3)
print(d)
#生成2-10数组,步长0.3
e = np.arange(2,10,0.3)
print(e)

三、linspace均分计算指令
linspace(x1,x2,N),其中x1、x2、N分别为起始值、终止值、元素个数(或者默认分成多的份数)。
f = np.linspace(0,100,100)
print(f)

网友评论