Python nbytes和getsizeof在整形后返回不同的值
这个问题与这里的问题有关: 我在一个numpy数组中测试了相同数量的数据,当我重新整形时,得到了不同的(很多)Python nbytes和getsizeof在整形后返回不同的值,python,arrays,numpy,Python,Arrays,Numpy,这个问题与这里的问题有关: 我在一个numpy数组中测试了相同数量的数据,当我重新整形时,得到了不同的(很多)getsizeof值。下面是我测试的代码 from sys import getsizeof import numpy as np test_array = np.asarray(np.arange(1000000.0)).reshape(1000, 1000) print("Real size of test array is {:,.0f}".format(getsizeof(te
getsizeof
值。下面是我测试的代码
from sys import getsizeof
import numpy as np
test_array = np.asarray(np.arange(1000000.0)).reshape(1000, 1000)
print("Real size of test array is {:,.0f}".format(getsizeof(test_array)))
print("NP size of test array is {:,.0f}".format(test_array.nbytes))
结果:
Real size of test array is 112
NP size of test array is 8,000,000
没有重塑
from sys import getsizeof
import numpy as np
test_array = np.asarray(np.arange(1000000.0))
print("Real size of test array is {:,.0f}".format(getsizeof(test_array)))
print("NP size of test array is {:,.0f}".format(test_array.nbytes))
我得到:
Real size of test array is 8,000,096
NP size of test array is 8,000,000
阅读有关numlpy视图的信息。请参见“谢谢hpaulj!”!这回答了你的问题吗?