mercredi 17 janvier 2018

Numpy doesnt return a value or a simple list but like 30 empty nested lists?

Currently I have an OrderedDict object that looks something like this:

OrderedDict([('počivaj', 2), ('v', 2), ('ki', 1), ('šibki', 1), ('še', 1), ('srečno', 1), ('popji', 1), ('le', 1), ('ko', 1), ('let', 1), ('angelj', 1), ('rože', 1), ('mlade', 1), ('mirno', 1), ('ne', 1), ('zibki', 1), ('topli', 1), ('dni', 1), ('cvet', 1), ('šteješ', 1)])

I'm using 2 different lists to get out a list of keys and a list of values.

first_word_keys = list(words.keys())
first_word_values = list(words.values())


Looks like this:
['v', 'počivaj', 'mlade', 'popji', 'ko', 'mirno', 'še', 'ne', 'topli', 'dni', 'angelj', 'le', 'šibki', 'cvet', 'let', 'šteješ', 'ki', 'rože', 'srečno', 'zibki']
[2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]

Now. I'm using Numpy's random choice function to choose a key based on the values of key(weighted random). Since numpy didnt let me use float values I'm using Integers using counter.

choiceX = np.random.choice(first_word_keys,first_word_values)

What this returns is really kind of remarkable:

[[[[[[[[[[[[[[[[[[[['popji']]]]]]]]]]]]]]]]]]

This is one of the words, hidden in a metric ton of empty nested lists. What did I do to make the numpy.random.choice() return such a weird list instead of just a value? I'm aware there are functions that could remove such a list, but I'm probably not using numpy correctly and would like to fix that before writing extra functions to remove empty nested lists.




Aucun commentaire:

Enregistrer un commentaire