Taimur
Taimur

Reputation: 3241

Numpy dot product results in `IndexError: only integers, slices...`

I'm trying to compute the dot product of two arrays like so:

for i in range(self.v_theta['shape'].shape[0] - 1):
   for j in range(self.v_theta['shape'].shape[1] - 1):
       self.theta['shape'][i, j] = \
           self.ratings[:, i].dot(self.v_ksi[:, i, j])

but am getting the following error:

self.ratings[:, i].dot(self.v_ksi[:, i, j])
IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices

I've checked the type of i and j, and they're definitely integers, and the colons are surely slices. I've also double checked the shapes of the arrays and the setup above is definitely legitimate for a dot product.

self.ratings and self.v_ksi are both of type <type 'numpy.ndarray'>

Any ideas?

Thanks!

Upvotes: 1

Views: 440

Answers (1)

user2357112
user2357112

Reputation: 280973

Most likely, the error is actually coming from this part of the code:

        self.theta['shape'][i, j] = \
        ^^^^^^^^^^^^^^^^^^^

The error message just confusingly points to the last physical line of the logical line on which the error occurred.

Perhaps you meant self.v_theta instead of self.theta.

Upvotes: 1

Related Questions