python - 创建大小为 2e5 的随机数组时 VisibleDeprecationWarning

标签 python arrays numpy scipy

我将 var1、var2 定义为以下数组:

N = 2e5
var1 = np.array(50 * np.random.normal(size=N) + 0.1)
var2 = np.array(0.01 * np.random.normal(size=N) - 300)

在 python 中运行这 3 个语句时,我收到以下两个警告:

__main__:7: VisibleDeprecationWarning: using a non-integer number instead of an integer will result in an error in the future

__main__:8: VisibleDeprecationWarning: using a non-integer number instead of an integer will result in an error in the future

如何纠正这个问题?

最佳答案

大小必须是整数。您使用了 N=2e5 但那是一个 float ,您可以只使用 2 * 10**5:

>>> type(2e5)
float

>>> type(2*10**5)
int

或者以其他方式将值转换为整数。

关于python - 创建大小为 2e5 的随机数组时 VisibleDeprecationWarning,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43985277/

相关文章:

python - OpenCV:以给定角度穿过轮廓质心的线

python - 仅使模型字段的一部分在 Django 中可用

c# - 如何为数组中的对象创建事件?

arrays - 创建另一个表和在 postgres 中使用数组有什么区别

python - 对 NumPy 数组的一行求和

python - 从日期时间中提取时间以便在 Pandas 中进行比较

python - 有没有办法将参数传递给 Flask-ReSTLess GET_SINGLE 预处理器?

c - 在C中将数字数组乘以int

python - 如何添加新的行和列来填充 numpy 数组

python - 每日数据,每 3 天重新采样,有效计算尾随 5 天