Howdy,<br><br><div><span class="gmail_quote">On 2/17/06, <b class="gmail_sendername">Brian Blais</b> <<a href="mailto:bblais@bryant.edu">bblais@bryant.edu</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Colin J. Williams wrote:<br>> Brian Blais wrote:<br>>> In my attempt to learn python, migrating from matlab, I have the<br>>> following problem. Here is what I want to do, (with the wrong syntax):<br>>>
<br>>> from numpy import *<br>>><br>>> t=arange(0,20,.1)<br>>> x=zeros(len(t),'f')</blockquote><div><br>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
<br><br> x=zeros(len(t),'d')<br>
<br>should work. Or the zeros_like() that Travis suggested.<br><br></div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">>><br>>> idx=(t>5) # <---this produces a Boolean array, probably not what you want.
<br>>> tau=5<br>>> x[idx]=exp(-t[idx]/tau) # <---this line is wrong (gives a TypeError)<br>>></blockquote><div><br><br>You could also use <br> idx=where(t>5)<br>In place of <br> idx=(t>5)<br>
<br>Although in this case it probably doesn't make much difference, where(expr) is more directly equivalent to matlab's find(expr).<br><br>See <a href="http://www.scipy.org/Wiki/NumPy_for_Matlab_Users">http://www.scipy.org/Wiki/NumPy_for_Matlab_Users
</a> for more Matlab equivalents. And consider contributing your own, if you have some good ones that aren't there already.<br><br>--bb<br></div><br></div>