TypeError: cannot perform reduce with flexible type

created at May 9, 2021, 11:01 a.m. views: 0

Description

In python, if you meet this error, it means:

You wrote numbers in the form of strings, and you use methods for numbers to deal with these strings.

Example

I create an “numeric” array in the form of strings:

array = np.array([['1', '2', '3'], ['4', '5', '6']])

then, I try to obtain the average of this array:

>>> np.average(array)
...
TypeError: cannot perform reduce with flexible type.

I get this error.

Solution

Just transfer your strings to numbers.

Please log in to leave a comment.