numpy常用语法

增加维度:

np.expand_dims(distance, 0)   

np.expand_dims(distance, 1)

np.expand_dims(distance, 2)

求平均值/最大/最小值:

 np.mean()/ np.max()/ np.min()

相邻元素差分

 arc_diff = np.diff(arc_hour)

判断数组是否全为某个值

is_constant = np.all(arc_diff == 1)

 判断数组是否含有某个值

is_constant = np.any(arc_diff == 1)

 随机返回一个整数:

numpy.random.randint(low, high)
# 范围从低(包括)到高(不包括),即[low, high)。如果没有写参数high的值,则返回[0,low)的值。
exmple: 
np.random.randint(2,10)  # 输出 9

 新建空数组动态添加

train_input =  np. empty([0, seq_length, 6], dtype=float)
train_input = np.append(train_input, curr_train_input, axis=0)

 二值化数组

np.where(a>threshold, upper, lower)

>>> a = np.random.rand(4, 4)
>>> a
array([[0.40619068, 0.5697802 , 0.62462315, 0.72661899],
       [0.09580956, 0.86708781, 0.82974038, 0.38233455],
       [0.69538282, 0.48197051, 0.48655537, 0.5986295 ],
       [0.44688326, 0.41067639, 0.79687831, 0.37464955]])
>>> threshold, upper, lower = 0.5, 1, 0
>>> b = np.where(a>threshold, upper, lower)
>>> b
array([[0, 1, 1, 1],
       [0, 1, 1, 0],
       [1, 0, 0, 1],
       [0, 0, 1, 0]])
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值