Efficient Python array with 100 million zeros?

后端 未结 10 699
挽巷
挽巷 2020-12-08 19:56

What is an efficient way to initialize and access elements of a large array in Python?

I want to create an array in Python with 100 million entries, unsigned 4-byte

10条回答
  •  暖寄归人
    2020-12-08 20:38

    Try this:

    x = [0] * 100000000
    

    It takes just a few seconds to execute on my machine, and access is close to instant.

提交回复
热议问题