使用Numpy创建网格网格时,如何更改整数类型?

2024-09-28 17:20:17 发布

您现在位置:Python中文网/ 问答频道 /正文

我犯了以下错误

MemoryError: Unable to allocate 201. GiB for an array with shape (2999, 2999, 2999) and data type int64

使用以下代码使用Numpy创建网格网格时

dimension=3
tot_length=2000
list_no=range(1, tot_length)
arr = np.meshgrid ( *[list_no for _ in range ( dimension )] )

我可以知道在哪里将int64更改为int32,或者其他可能的设置,允许我最大化大于值2000tot_length数吗

我已经检查了documentation,但是它没有声明将数据类型更改为type32的选项


Tags: tono网格for错误rangelengthlist
1条回答
网友
1楼 · 发布于 2024-09-28 17:20:17

May I know where to change the int64 to int32

NumPy猜测int64,因为您给它一个range对象,它需要一个数组,而rangeint的序列。如果不想让数组猜测,请使用数组:

list_no = np.array(range(1, tot_length), dtype=np.int32)

或者更简单地说

list_no = np.arange(1, tot_length, dtype=np.int32)

当然,您仍然需要100Gib的内存,这仍然相当大

相关问题 更多 >