莫名其妙的早就安装了一个numpy库,未确定是否是个完整的库,
numpy.version.version 查看版本号
基础概念:对象是同种元素的多位数组
维度称为轴
轴的个数称为秩
其提供矩阵运算功能,一般与scipy,matplotlib
创建数组:
numpy.array(x) x为列表list或tuple
tset=numpy.array(((1,2,3),(4,5,6),(7,8,9)))
test
([[1,2,3],[4,5,6],[7,8,9]])
x也可以是( [ [ ] ] )或者是( ( [ ] ) )
上面的方法都是创建一个二维数组
test.shape
(3,3)
test.type
‘int32’
如果维的长度不等,则不显(后面的3不要)
已知类别:‘int32’,’float64’,’|sx’ x为维的长度
定义类别,在第0位添加
((()),dtype=(int32 | float64 | numpy.string_)
可通过numpy.shape 改造数组
a=numpy.array(((1,2,3,4),(4,5,6,7),(7,8,9,10)))
a.shape
(3,4)
有两个维度,第0维长度为3,第一维长度为4
a.shape=(4,3)
array([
[1,2,3],
[4,4,5],
[6,7,7],
[8,9,10]
]
)
数组元素不变((m*n)=(m’*n’)),数组每个轴的长度发生改变,数组元素在内存中的位置没有变