NumPy--大锅菜

用于记录,便于巩固与复习

 

np.random.uniform()---均匀取值

numpy.random.uniform(low=0.0, high=1.0, size=None)
# 从[low, high])中均匀取值,没有任何参数的话,是从[0, 1)

np.random.permutation()---随机排序

np.random.permutation(5)
# [2,1,0,3,4]

np.random.permutation([1,2,3,4,5])
# [2,3,4,1,5] 对列表里面的元素随机排序

np.random.permutation([[0,1,2],
                       [3,4,5],
                       [6,7,8]])
# [[3,4,5],
   [0,1,2],
   [6,7,8]]  仅在一维排序

np.random.rand() --- 生成指定维度的的[0,1)范围之间的随机数,输入参数为维度

np.random.randn() --- 生成指定维度的服从标准正态分布的随机数,输入参数为维度

np.random.randint(low, high = None, size = None,dtype = 'l')--- 返回随机数或者随机数组成的array

np.random.seed() -->使随即数据可预测,对于同一个seed,生成的随机数相同

np.where(condition, x, y)

# np.where(condition, x, y) 满足条件(condition),输出x,不满足输出y。

np.where([[True,False], [True,True]],    # 官网上的例子
             [[1,2], [3,4]],
             [[9,8], [7,6]])

>>> array([[1, 8],[3, 4]])

# np.where(condition)

a = np.array([2,4,6,8,10])
np.where(a > 5)             # 返回索引
>>> array([2, 3, 4])
   
a[np.where(a > 5)]              # 等价于 a[a>5]
>>> array([ 6,  8, 10])

np.mean() --求均值

import numpy as np
np.mean(x,       # 带求均值的数值
        axis,    # axis = 0 每列每列求均值,返回 1 * n矩阵; axis = 1 每行每行求均值,返回m*1
        dtype,   # 返回数值类型
        out,
        keepdims )    # 返回值保持原数组维度,默认为false

a = np.array([1,2,3,4])
np.mean(a, axis = 0,keepdims = True)

>>> array([2.5])

np.mean(a, axis = 0,keepdims = False)

>>> 2.5

np.tile() ---以行复制或者列,或者同时复制

Examples
    --------
    >>> a = np.array([0, 1, 2])
    >>> np.tile(a, 2)
    array([0, 1, 2, 0, 1, 2])
    >>> np.tile(a, (2, 2))
    array([[0, 1, 2, 0, 1, 2],
           [0, 1, 2, 0, 1, 2]])
    >>> np.tile(a, (2, 1, 2))
    array([[[0, 1, 2, 0, 1, 2]],
           [[0, 1, 2, 0, 1, 2]]])

    >>> b = np.array([[1, 2], [3, 4]])
    >>> np.tile(b, 2)
    array([[1, 2, 1, 2],
           [3, 4, 3, 4]])
    >>> np.tile(b, (2, 1))
    array([[1, 2],
           [3, 4],
           [1, 2],
           [3, 4]])

    >>> c = np.array([1,2,3,4])
    >>> np.tile(c,(4,1))
    array([[1, 2, 3, 4],
           [1, 2, 3, 4],
           [1, 2, 3, 4],
           [1, 2, 3, 4]])
    """

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值