[Numpy-discussion] simple question
Mathew Yeates
myeates at jpl.nasa.gov
Thu Jul 6 16:23:49 EDT 2006
Not working.
A[row,all_dates == 10] = -1 where all_dates is a matrix with column
length of 14 [[960111,..,..
and A is a matrix with same column length
I get
IndexError: arrays used as indices must be of integer type
when I print out all_dates == 10
I get
[True True True True True True True True True False False False True True]]
I experimented with "<" instead of "==" but I still get boolean values
as indices.
Any help?
Mathew
Keith Goodman wrote:
> On 7/5/06, Mathew Yeates <myeates at jpl.nasa.gov> wrote:
>> What is the typical way of doing the following
>> starting with a 0 matrix, set all values to 1 when a certain condition
>> is met, set to -1 when another condition is met, left alone if neither
>> condition is met.
>
> This works on recent versions of numpy:
>
>>> x = asmatrix(zeros((2,2)))
>
>>> x
>
> matrix([[0, 0],
> [0, 0]])
>
>>> y = asmatrix(rand(2,2))
>
>>> y
>
> matrix([[ 0.85219404, 0.48311427],
> [ 0.41026966, 0.2184193 ]])
>
>>> x[y > 0.5] = 1
>
>>> x[y < 0.5] = -1
>
>>> x
>
> matrix([[ 1, -1],
> [-1, -1]])
>
More information about the NumPy-Discussion
mailing list