numpy学习笔记(一、ndarray数组)
1.ndarray数组
注意.shape()函数德返回值为元组类型。
注意ndarray对象尽量要同质,其中x.shape返回值为(2,)为元组,单个元素作为元组时要在末尾加上逗号。
2.创建ndarray数组
注意,再不指定数组元素类型时(不指定dtype时),使用array()函数创建德默认为整数类型,其余函数默认为浮点数类型。
import numpy as np
np.array(10)
Out[2]: array(10)
np.ones((3,6))
Out[3]:
array([[1., 1., 1., 1., 1., 1.],
[1., 1., 1., 1., 1., 1.],
[1., 1., 1., 1., 1., 1.]])
np.zeros((3,6),dtype=np.int32)
Out[4]:
array([[0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0]])
np.eye(5)
Out[6]:
array([[1., 0., 0., 0., 0.],
[0., 1., 0., 0., 0.],
[0., 0., 1., 0., 0.],
[0., 0., 0., 1., 0.],
[0., 0., 0., 0., 1.]])
3.ndarray数组变换
4.ndarray数组操作
5.ndarray数组的计算
一元函数:
二元函数: