python 数据处理 - numpy模块

python 数据处理 - numpy 模块

1.np.array()

Parameters
  • object: array_like
  • dtype: data-type, optional
  • copy: bool, optional
  • order{‘K’, ‘A’, ‘C’, ‘F’}, optional
# 示例1
data = np.array(data,dtype=np.float)

2.np.where()

numpy.``where(condition[****, x**,** y**]****)**

Description:

Return elements chosen from x or y depending on condition.

Parameters:
Parameters
  • condition: array_like, bool

    Where True, yield x, otherwise yield y.

  • x, y: array_like

    Values from which to choose. x, y and condition need to be broadcastable to some shape.

# 示例1
data.loc[i, 'total_current'] = np.average(temp1,weights=temp2)

3.np.average

Parameters
  • a: array_like

  • axis: None or int or tuple of ints, optional

    Axis or axes along which to average a.

  • weights: array_like, optional

  • returnedbool, optional

    Default is False. If True, the tuple (average, sum_of_weights) is returned, otherwise only the average is returned. If weights=None, sum_of_weights is equivalent to the number of elements over which the average is taken.

# 示例1
data.loc[i, 'total_current'] = np.average(temp1,weights=temp2)

4. np.random.choice

import numpy as np

# 参数意思分别 是从a 中以概率P,随机选择3个, p没有指定的时候相当于是一致的分布
a1 = np.random.choice(a=5, size=3, replace=False, p=None)
print(a1)
# 非一致的分布,会以多少的概率提出来
a2 = np.random.choice(a=5, size=3, replace=False, p=[0.2, 0.1, 0.3, 0.4, 0.0])
print(a2)
# replacement 代表的意思是抽样之后还放不放回去,如果是False的话,那么出来的三个数都不一样,如果是
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值