python numpy

来源:互联网 发布:python sorted key 编辑:程序博客网 时间:2024/05/17 18:00

numpy.atleast_2d(*arys)
把输入看成至少有两个dimension的array
Parameters:
arys1, arys2, … : array_like
形似数组的序列,不是数组被转为数组,dimension>=2保留
Returns:
res, res2, … : ndarray
An array, or list of arrays, each with a.ndim >= 2. Copies are avoided where possible, and views with two or more dimensions are returned.

print(np.atleast_2d(3))print(np.atleast_2d([1,3,5]))print(np.atleast_2d(2,[1,5,7],[[3,5,6]]))b = atleast_2d(np.ones([6],dtype='double'))print(b)a = atleast_2d(array([], dtype ='double'))print(a.shape)输出:[[3]][[1 3 5]][array([[2]]), array([[1, 5, 7]]), array([[3, 5, 6]])][ 1.  1.  1.  1.  1.][[ 1.  1.  1.  1.  1.  1.]](1L, 0L)

numpy.random.random(size=None)

Parameters:
整数或者整数元组eg.(m,n,k)
Returns:
m*n*k的numpy array,数字是[0.0,1.0)之间的随机数

a =(2*np.random.random((2,2))-1)*0.25print(a)print(np.random.random(2))ouput:[[ 0.10663787 -0.18734724] [-0.20742755  0.20437032]][ 0.7854141   0.22205561]
1 0
原创粉丝点击