python-numpy最全攻略十-random_sample, ranf, bitwise

本文深入探讨Python的NumPy库,重点讲解np.random_sample()函数用于生成随机样本,random.ranf()方法生成浮点随机数,以及NumPy中的位运算函数用法。通过实例解析这些功能,帮助读者理解并掌握Python数值计算中的随机数生成与位操作。
摘要由CSDN通过智能技术生成
  1. np.random_sample()
 importing numpy 
import numpy as np
  
# output random value 
out_val = np.random.random_sample() 
print ("Output random float value : ", out_val)
Output random float value :  0.2450768662139805
import numpy as geek 
  
  
# output array 
out_arr = geek.random.random_sample(size =(1, 3)) 
print ("Output 2D Array filled with random floats : ", out_arr)  
Output 2D Array filled with random floats :  [[0.15468058 0.26536462 0.54954387]]
import numpy as geek 
# output array 
out_arr = geek.random.random_sample((3, 2, 1)) 
print ("Output 3D Array filled with random floats : ", out_arr)  
Output 3D Array filled with random floats 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值