标题中提到的Float64数组和float32数组在传输dtype之前是相同的数组。
>>>tf.data
array([[ 0.4323222 , 0.43547374, 0.44253287, ..., 0.47413033,
0.47939426, 0.48931041],
[ 0.43846995, 0.44194463, 0.44968641, ..., 0.47143713,
0.478816 , 0.49225217],
[ 0.45199326, 0.45617312, 0.46540445, ..., 0.46566921,
0.47759479, 0.49858749],
...,
[ 0.28666443, 0.29013845, 0.29773292, ..., 0.34627852,
0.34814295, 0.34780815],
[ 0.28523368, 0.29085371, 0.30313784, ..., 0.33980089,
0.34118292, 0.34012163],
[ 0.28374609, 0.29204369, 0.31018677, ..., 0.32426074,
0.32583919, 0.32578641]], dtype=float32)
>>>data
array([[ 0.43232219, 0.43547375, 0.44253288, ..., 0.47413034,
0.47939425, 0.48931042],
[ 0.43846994, 0.44194463, 0.4496864 , ..., 0.47143714,
0.478816 , 0.49225218],
[ 0.45199327, 0.45617312, 0.46540444, ..., 0.46566923,
0.47759479, 0.4985875 ],
...,
[ 0.28666442, 0.29013845, 0.29773293, ..., 0.34627851,
0.34814295, 0.34780817],
[ 0.28523367, 0.2908537 , 0.30313784, ..., 0.33980089,
0.34118291, 0.34012163],
[ 0.2837461 , 0.29204368, 0.31018678, ..., 0.32426075,
0.3258392 , 0.32578641]])
>>> tf.data.dtype
dtype('float32')
>>> data.dtype
dtype('float64')
>>> import sys
>>> sys.getsizeof(tf.data)
6836
>>> sys.getsizeof(data)
112
为什么float64数组是112,但float32数组是6836?
**********************我无法回答我的问题****************** *******
**********************我有答案********************* ************
哦,我知道答案,感谢来自@ user2357112和@ user2699的答案。 数据只是指向保存在其他地方的真实对象的指针。在我的终端中有一些测试“size_question”。
>>> c=np.arange(100).reshape(10,10)
>>>c.dtype
dtype('int32')
>>> sys.getsizeof(c)
112
>>> e=np.int32(c)
>>> sys.getsizeof(e)
112
>>> f = c.astype(np.int32)
>>> sys.getsizeof(f)
512
>>> e=np.int8(c)
>>> sys.getsizeof(e)
212
>>> f = c.astype(np.int8)
>>> sys.getsizeof(f)
212
>>>