mardi 7 juillet 2020

How to fill a zeros matrix with an extremely low density of ones

I have a 3D matrix of zeros of size (850,850,850) and I would like to insert ones in this matrix in an homogeneous way with an extremely low density=8*10^-7. I tried to use the random.sparse (which worked for higher density) but it doesn't work, I think the density is too low and it's approximated to zero, in fact there are no ones where indeed there should be 50 ones. here it's the code for better understanding:

import numpy as np
import random

space=np.zeros(shape=(850,850,850))
den=50/(850*850*850)
for k in range (0,850): 
   rdm_space=sparse.random(850, 850, density=den, data_rvs=np.ones)
   rdm_space=rdm_space.toarray()                                                                 
   space[:][:][k] = vac_space

Does someone have any suggestions? Thanks




Aucun commentaire:

Enregistrer un commentaire