当您存储一个没有足够的内存分配的numpy阵列时会发生什么?
我只是在与NP.array及其内存分配一起玩,我希望如果您尝试存储一个对于内存分配太大的数组,您只会遇到错误,或者只会存储第一个X数字数字。相反,我只是回来了似乎是随机的数字。幕后发生了什么?
import numpy as np
def create_new_array(num_list):
new_array = np.array(num_list,np.int8)
return print(new_array)
create_new_array([31112 , 32321, 24567,456,324,789])
输出: [-120,65,-9,-56,68,21]
更改输入值稍微给出了完全不同的输出,我对此非常好奇。
I was just playing around with np.array and its memory allocation, I expected that if you tried to store an array that was too big for the memory allocation you would just get an error or would just store the first x number of digits. Instead I just got back seemingly random numbers. What is going on behind the scenes here?
import numpy as np
def create_new_array(num_list):
new_array = np.array(num_list,np.int8)
return print(new_array)
create_new_array([31112 , 32321, 24567,456,324,789])
output:
[-120, 65, -9, -56, 68, 21]
Changing the input values slightly gives completly differnt outputs and I'm very curiouse as to why this is.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
数字不是随机的;它们是补充。对于
int8
,它可以表示的最大正数为127,在此上面返回了数字的补充。例如:The numbers are not random; they are the complements. For
int8
, the maximum positive number it can represent is 127, above which the numbers' complements are returned. For example: