[Numpy-discussion] Assignment when there is nothing to assign

Keith Goodman kwgoodman at gmail.com
Thu Dec 21 12:28:40 CST 2006


I have the following two lines in a for loop:

if len(idx):
    x[idx,i] = x[idx,i-1]

where idx is the output of a where statement.

I need the 'if len(idx)' line to prevent an error when idx is empty.

Would it make sense to allow

x[idx,i] = x[idx,i-1]

when idx is empty instead of raising an error?

The error I get is

ValueError: array is not broadcastable to correct shape


More information about the Numpy-discussion mailing list