lundi 29 mars 2021

generating huge amout of random numbers with python

I want to generate random numbers, uniformly between -1 and 1. I know that using NumPy and generating an array of numbers is much better than generate the one by one in a for loop. On the other hand, I want these numbers to operate with them only once, so there's no reason for storing them in an array. My question is, what is the best solution to this, on one hand using a for loop is not time efficient, but I don't store unnecessary numbers, I generate them one by one and then I throw them. On the other hand, an array is not memory efficient, since if I want to generate 10^10 numbers, I need to create a 10^10 size array, with horrible results. I assume the best choice is to generate small arrays (10^3 or 10^4 elements) one by one, but I want to know if there's a better solution to this problem (maybe a NumPy function that generates the numbers but creates something like an iterable that don't store all them in memory?)




Aucun commentaire:

Enregistrer un commentaire