I'm trying to find the maximal value of a list of lists of numbers.
Using Python 2.7 IDLE, I tried this:
import numpy
vectors = [[1, 2, 3], [4,5,6]]
numpyFiles = numpy.array(vectors)
maxRawFreq = numpyFiles.max()
It works, and maxRawFreq = 6
I tried using a very similar code, with a much bigger list, and using Pydev (Eclipse), but I get the following error:
cannot perform reduce with flexible type
What does it mean? (other SO questions about this error gave too specific solutions...).
My code:
import numpy
with open(inputFile) as f:
vectors = f.readlines()
vectorLength=len(vectors[0])#number of columns (word vector length)
numpyFiles = numpy.array(vectors)
#both these line gave me the same error:
#maxRawFreq = numpyFiles.max()
maxRawFreq = numpy.max(numpyFiles)
My inputFile contains numbers, like so:
-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-1, 0, 0, 3, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0,
+1, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6,
numpy.loadtxtornumpy.genfromtxtto load the data from the file?file.readlinessimply returns a list of lines from the file. - Ashwini Chaudhary