mardi 12 novembre 2019

numpy random choice returning floating numbers

In my code, I randomly generate indices of a large numpy array using the code

import numpy as np
random = np.random.RandomState(seed=1000)

r = 140000
c = 30000
k = 210000000
flat_indx = random.choice(xrange(r*c),k,replace=False)

But it returns floating number and because of that my code for unravel fails

Indx = np.unravel_index(flat_indx,(U,I))

This is what I got when I tried it on python shell

> random.choice(xrange(140000*30000),10,replace=False) array([2.63189959e+09, 9.52388615e+08, 2.79972090e+09, 1.66392341e+09,
>        3.96565768e+09, 4.18275392e+09, 2.18902320e+07, 2.54430836e+09,
>        1.52407003e+08, 3.36787629e+09])

How can I get it corrected ?




Aucun commentaire:

Enregistrer un commentaire