0

When i run this function - I get the following error below: I also checked my numpy version is 1.14 (which is higher than 1.7 when this issue was reported/resolved previously) - but still cant get to run this without error.

def rank_to_dict(ranks, names, order=1):  
    minmax = MinMaxScaler()  
    ranks = minmax.fit_transform(order*np.array([ranks]).T).T[0]  
    ranks = map(lambda x: round(x, 2), ranks)  
    return dict(zip(names, ranks ))  

Error
<ipython-input-12-d23066e235d3> in rank_to_dict(ranks, names, order)  
     21 def rank_to_dict(ranks, names, order=1):  
     22     minmax = MinMaxScaler()  
---> 23     ranks = minmax.fit_transform(order*np.array([ranks]).T).T[0]  
     24     ranks = map(lambda x: round(x, 2), ranks)  
     25     return dict(zip(names, ranks ))  

TypeError: unsupported operand type(s) for *: 'int' and 'map  
Emre
  • 10,491
  • 1
  • 29
  • 39
Patrick
  • 139
  • 4

1 Answers1

1

I couldn't think of a situation, where np.array would return a map, however if your input ranks is a map, it seems you do get an array of map objects back!

Here is an example:

In [1]: ranks = map(lambda x, y: x + y, [1, 2, 3, 4], [2, 3, 4, 5])

In [2]: ranks
Out[2]: <map at 0x7f79d79c0e10>

In [3]: np.array(ranks)
Out[3]: array(<map object at 0x7f79d79c0e10>, dtype=object)

In [4]: 1 * ranks
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-34-ff69339d7f75> in <module>()
----> 1 1 * ranks

TypeError: unsupported operand type(s) for *: 'int' and 'map'

I create a map object (just adds the two lists element-wise), then create a numpy array of that map. If I multiply it by an integer, I get your error.

You need to therefore make sure that your input argument ranks is not a map object. If you provide more information as to what it is, maybe I can help convert it as necessary.

n1k31t4
  • 14,858
  • 2
  • 30
  • 49