Python, tuple indices must be integers, not tuple?

Your output variable is not a N x 4 matrix, at least not in python types sense. It is a tuple, which can only be indexed by a single number, and you try to index by tuple (2 numbers with coma in between), which works only for numpy matrices. Print your output, figure out if the problem is just a type (then just convert to np.array) or if you are passing something completely different (then fix whatever is producing output).

Example of what is happening:

import numpy as np
output = ((1,2,3,5), (1,2,1,1))

print output[1, 2] # your error
print output[(1, 2)] # your error as well - these are equivalent calls

print output[1][2] # ok
print np.array(output)[1, 2] # ok
print np.array(output)[(1, 2)] # ok
print np.array(output)[1][2] # ok

Leave a Comment

tech