nump学习笔记

1.ndarray:stands for N-dimensional array,all items are of  the same type and the same size.their size is fixed.

2.define a new ndarray:use the array()funciton,passing a python list/tuple containing the elements .

a=np.array([1,2,3,4,5,6,])    b=np.array((1,2,3)),

也可列表与元组混用:-----c=np.array([(1,2,3),[4,5,6],(7,8,9)])

也可定义元素类型:-------d=np.array([[1,2],[3,4]],dtype=complex)

3.check object is an ndarray:by type() function--------------------------type(a)

4.check elements type:---------------------------------a.dtype

5.get the axes:--------------------------a.ndim

6.get the length:--------------------------a.size

7.get the shape:--------------------a.shape

8.the size in bytes of each item in the array:--------------------------------a.itemsize

9.indexing mechanism:------------------------------a.data

10.np.zeros((3,3))创建3x3的全0的ndarray,

     np.ones((3,3))创建3x3的全1的ndarray,

     q=np.arange(0,10,1)创建0到9步长为1的一维序列矩阵。 --------改变形状:q.reshape(2,5),变成2行5列。

  p=np.linspace(0,10,5)创建0到10均匀5个数的一维序列矩阵。

     np.random.random(3)  随机生成0到1的三个一维array

     np.random.random((3,3))随机生成0到1的3行3列array

 11.ndarray+4具有广播操作,array的每个元素都加4(加减乘除数字都具有此广播作用)

      ndarray1加减乘除ndarray2:--------对应位置加减乘除操作

12.数学运算:a*np.sin(b)   a*sqrt(b),都是对应元素做数学运算

13array做矩阵运算:np.dot(A,B)或A.dot(B)矩阵乘法

 14对ndarray内部元素做操作:a.sum()a内的元素全部相加;a.min()a内最小的元素;a.max();a.mean();a.std()a的标准差

猜你喜欢

转载自www.cnblogs.com/Turing-dz/p/11692467.html