numpy用法

来源:互联网 发布:jquery 删除二维数组 编辑:程序博客网 时间:2024/06/07 03:55

http://www.numpy.org/

numpy reference:
https://docs.scipy.org/doc/numpy/reference/

numpy quickstart tutorial:
https://docs.scipy.org/doc/numpy/user/quickstart.html

https://docs.scipy.org/doc/numpy/reference/arrays.ndarray.html

1 创建ndarray

https://docs.scipy.org/doc/numpy/reference/routines.array-creation.html#routines-array-creation

import numpy as nparr = np.array([1, 3, 5, 7])arr1 = np.array([[1, 2, 3], [4, 5, 6]])print arrprint arr * arrprint arr -arrprint 1.0 / arrprint arr ** 0.5, '\n'print arr1, '\n'print arr1.shape, '\n'

输出:
这里写图片描述

2 一些小知识点

2.1 属性

ndarray属性:

ndarray.shape #Tuple of array dimensions.

2.2 方法

numpy.nonzero(a) #return the indices of the elements that are non-zero
numpy.argsort() #returns the indices that would sort an array.import numpy as npx = np.array([3, 1, 2])print x.argsort()print x.argsort()[:-4:-1] # -1代表步长[1 2 0][0 2 1]
原创粉丝点击