0

I am probably missing something obvious but I am stuck on this:

Inside ipdb session I was able to reduce my problem to this:

ipdb> type(scores)
<class 'numpy.matrixlib.defmatrix.matrix'>
ipdb> scores.shape
(23073, 50)
ipdb> scores[np.arange(scores.shape[0]), np.zeros(scores.shape[0], dtype=np.int)] += 10
*** ValueError: array is not broadcastable to correct shape
ipdb> scores.dtype
dtype('float64')

I was not able to reproduce this problem with at simple example:

In [24]: a = np.matrix(np.zeros((6,4))
)

In [25]: a[np.arange(a.shape[0]), np.zeros(a.shape[0], dtype=np.int)] += 10

In [26]: a
Out[26]: 
matrix([[ 10.,   0.,   0.,   0.],
        [ 10.,   0.,   0.,   0.],
        [ 10.,   0.,   0.,   0.],
        [ 10.,   0.,   0.,   0.],
        [ 10.,   0.,   0.,   0.],
        [ 10.,   0.,   0.,   0.]])

In [27]: a.dtype
Out[27]: dtype('float64')

Any ideas what could be going on? What should I check?

2
  • Are you trying to add 10 to the first column? Try a[:,0] += 10. Commented Mar 11, 2015 at 16:17
  • I was trying to do something more complicated, I just kept simplifying and go the this. Commented Mar 11, 2015 at 16:18

1 Answer 1

1

OK, I figured it out. On my local (simple example) I have numpy 1.9.0 and on remote (ipdb session) I have numpy 1.8.1

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.