numpy的基础知识

3 篇文章 0 订阅
2 篇文章 0 订阅
每一个数组中包含n个数组,每一个数组的元素即可以是单一元素,也可能是对象元素(把数组内的数组看作一个对象)


基础
在numpy中dimensions(纬度)被称为axes(轴),轴的个数又被称为rank,轴又被称为shape
ndarray.ndim
the number of axes (dimensions) of the array. In the Python world, the number of dimensions is referred to asrank.
数组的维度的个数。
ndarray.shape
the dimensions of the array. This is a tuple of integers indicating the size of the array in each dimension. Fora matrix with n rows and m columns, shape will be (n,m). 
The length of the shape tuple is therefore therank, or number of dimensions, ndim. 
数组的维度。这个整数的元组表明这个数组的每一个纬度的len(就是数组元素的个数)。rows是行,columns是列,matrix(矩阵,就是个多维数组)(n,m),

    rand(d0, d1, ..., dn)
    
    Random values in a given shape.
    
    Create an array of the given shape and populate it with
    random samples from a uniform distribution
    over ``[0, 1)``.
    
    Parameters
    ----------
    d0, d1, ..., dn : int, optional
        The dimensions of the returned array, should all be positive.
        If no argument is given a single Python float is returned.
    
    Returns
    -------
    out : ndarray, shape ``(d0, d1, ..., dn)``
        Random values.
>>> np.random.rand(1)        一维数组
array([ 0.79745586])
>>> np.random.rand(2)        一维数组
array([ 0.69761923,  0.84220923])
>>> np.random.rand(1,2)      二维数组
array([[ 0.49782588,  0.8097365 ]])
>>> np.random.rand(1,2,3)    三维数组
array([[[ 0.7976663 ,  0.66164786,  0.45544674],
        [ 0.31074188,  0.48867015,  0.34878639]]])
>>> 

>>> np.random.rand(1).ndim  一维数组的rank
1
>>> np.random.rand(2).ndim  一维数组的rank
1
>>> np.random.rand(1,2).ndim 二维数组的rank
2
>>> np.random.rand(1,2,3).ndim 三维数组的rank
3
>>> np.random.rand(1).shape    一维数组的shape , 只有一行
(1,)
>>> np.random.rand(2).shape
(2,)
>>> np.random.rand(1,2).shape  二维数组的shape,1行2列
(1, 2)
>>> np.random.rand(1,2,3).shape 三维数组的shape,
(1, 2, 3)                       
>>> 
>>> np.random.rand(1,3,4)
array([[[ 0.59345269,  0.4729665 ,  0.09288839,  0.18189849],
        [ 0.56746188,  0.75279613,  0.19881335,  0.08361007],
        [ 0.32780258,  0.95874817,  0.83552499,  0.09640104]]])
>>>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值