Fastest way to grow a numpy numeric array

后端 未结 5 2110
后悔当初
后悔当初 2020-11-27 12:01

Requirements:

  • I need to grow an array arbitrarily large from data.
  • I can guess the size (roughly 100-200) with no guarantees that the array will fit
5条回答
  •  有刺的猬
    2020-11-27 12:29

    np.append() copy all the data in the array every time, but list grow the capacity by a factor (1.125). list is fast, but memory usage is larger than array. You can use array module of the python standard library if you care about the memory.

    Here is a discussion about this topic:

    How to create a dynamic array

提交回复
热议问题