官网文档镇楼 https://docs.scipy.org/doc/numpy-dev/user/quickstart.html
快速开始。
import numpy as np
初始化数组并且赋值为1,这里是一个2*3*4的高位数组,而且制定数据类型为int16位:
如果是0的话,那么就是np.zeros()
>>> np.ones( (2,3,4), dtype=np.int16 ) # dtype can also be specified
array([[[ 1, 1, 1, 1],
[ 1, 1, 1, 1],
[ 1, 1, 1, 1]],
[[ 1, 1, 1, 1],
[ 1, 1, 1, 1],
[ 1, 1, 1, 1]]], dtype=int16)
list 转 array
list=[]
a = np.array(list)
array 转list
b = a.tolist()
flat 平铺多维数组
>>> x = np.arange(1, 7).reshape(2, 3)
>>> x
array([[1, 2, 3],
[4, 5, 6]])
>>> x.flat[3]
4
>>> x.T
array([[1, 4],
[2, 5],
[3, 6]])
>>> x.T.flat[3]
5
>>> type(x.flat)
<type 'numpy.flatiter'>
# 下面是赋值
>>> x.flat = 3; x
array([[3, 3, 3],
[3, 3, 3]])
>>> x.flat[[1,4]] = 1; x
array([[3, 1, 3],
[3, 1, 3]])