dimanche 31 janvier 2016

DeprecationWarning: converting an array with ndim > 0 to an index will result in an error in the future

I have a matrix named data, which is filled with numbers. I wanted to pick a random row from it, so I did:

centroids.append(
data[np.random.randint(0, len(data), size=1)]
.flatten().tolist())

Now, I also have this dictionary:

category = { "World news": [0, 56 , 87], "Politics": [352654], ... }

and I would like to get a random row from data, but now I would like to pick the index from the i-th key's list.

Here is what I tried:

centroids.append(data[
  category.get(category.keys()[i])[
    np.random.randint(0, len(category.get(category.keys()[i])), size=1)
  ]
].flatten().tolist())

and I am getting this warning:

DeprecationWarning: converting an array with ndim > 0 to an index will result in an error in the future

What is happening? Is it simply the version of numpy the issue here?

Note that category.get(category.keys()[i] returns (for example) [4367, 7777].




Aucun commentaire:

Enregistrer un commentaire