(4)Numpy 矩阵计算 和生成
In [1]:
import numpy
1.创建一个矩阵¶
In [3]:
vector=numpy.array([1,2,3,4,5,6])
print(vector)
2.创建多维矩阵——常用最大值最小值函数¶
In [5]:
vector=numpy.array([
[1,2,3,4],
[1,2,3,4],
[1,2,3,5]
])
print(vector)
print("----最值------")
print(vector.min())
print(vector.max())
print(vector.sum())
In [7]:
print(vector.sum(axis=1))
print(vector.sum(axis=0))
In [10]:
ary=numpy.arange(15) #生产矩阵
print(ary)
ary=numpy.arange(1,50,2) #生产矩阵
print(ary)
In [9]:
ary.reshape(3,5)
In [23]:
ary.reshape(5,3)
Out[23]:
In [26]:
ary.size
Out[26]:
In [32]:
numpy.zeros((3,5))
Out[32]:
In [43]:
numpy.ones((2,3,2),dtype=numpy.int32)
Out[43]:
In [55]:
#随机数
numpy.random.random()
Out[55]:
In [65]:
#随机矩阵
numpy.random.random((2,3))
Out[65]:
这里是markdown¶
d