How to solve memory error in mtrand.RandomState.choice?

前端 未结 1 335
无人及你
无人及你 2021-01-14 14:00

I\'m trying to sample 1e7 items from 1e5 strings but getting a memory error. It\'s fine sampling 1e6 items from 1e4 strings. I\'m on a 64bit machine with 4GB RAM and don\'t

1条回答
  •  囚心锁ツ
    2021-01-14 14:44

    You can work round this using a generator function:

    def item():
        for i in xrange(N):
          yield "id%010d"%np.random.choice(N//K,1)
    

    This avoids needing all the items in memory at once.

    0 讨论(0)
提交回复
热议问题