您的位置:首页 > 编程语言 > Python开发

Python-Numpy(3)矩阵基本操作

2017-08-12 11:34 731 查看
import numpy as np
a = np.arange(15).reshape(3, 5)
a




a.shape




#the number of axes (dimensions) of the array
a.ndim#维度




a.dtype.name




#the total number of elements of the array
a.size




np.zeros ((3,4))




np.ones( (2,3,4), dtype=np.int32 )




#To create sequences of numbers
np.arange( 10, 30, 5 )




np.arange( 0, 2, 0.3 )




np.arange(12).reshape(4,3)




np.random.random((2,3))




from numpy import pi
np.linspace( 0, 2*pi, 100 )




np.sin(np.linspace( 0, 2*pi, 100 ))




#the product operator * operates elementwise in NumPy arrays
a = np.array( [20,30,40,50] )
b = np.arange( 4 )
#print a
#print b
#b
c = a-b
#print c
b**2
#print b**2
print a<35




#The matrix product can be performed using the dot function or method
A = np.array( [[1,1],
[0,1]] )
B = np.array( [[2,0],
[3,4]] )
print A
print B
#print A*B
print A.dot(B)
print np.dot(A, B)


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  numpy