|
From: Bill B. <wb...@gm...> - 2006-02-17 03:35:29
|
Howdy,
On 2/17/06, Brian Blais <bb...@br...> wrote:
>
> Colin J. Williams wrote:
> > Brian Blais wrote:
> >> In my attempt to learn python, migrating from matlab, I have the
> >> following problem. Here is what I want to do, (with the wrong syntax):
> >>
> >> from numpy import *
> >>
> >> t=3Darange(0,20,.1)
> >> x=3Dzeros(len(t),'f')
This was the line causing the type error. t is type double (float64). 'f'
makes x be type float32. That causes the assignment below to fail.
Replacing that line with
x=3Dzeros(len(t),'d')
should work. Or the zeros_like() that Travis suggested.
>>
> >> idx=3D(t>5) # <---this produces a Boolean array, probab=
ly
> not what you want.
> >> tau=3D5
> >> x[idx]=3Dexp(-t[idx]/tau) # <---this line is wrong (gives a TypeError=
)
> >>
You could also use
idx=3Dwhere(t>5)
In place of
idx=3D(t>5)
Although in this case it probably doesn't make much difference, where(expr)
is more directly equivalent to matlab's find(expr).
See http://www.scipy.org/Wiki/NumPy_for_Matlab_Users for more Matlab
equivalents. And consider contributing your own, if you have some good one=
s
that aren't there already.
--bb
|