Thanks Chris for informative post. <br><br>cheers,<br><br>Chao<br><br><div class="gmail_quote">2012/5/22 Chris Barker <span dir="ltr"><<a href="mailto:chris.barker@noaa.gov" target="_blank">chris.barker@noaa.gov</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">On Tue, May 22, 2012 at 6:33 AM, Chao YUE <<a href="mailto:chaoyuejoy@gmail.com">chaoyuejoy@gmail.com</a>> wrote:<br>

<br>
> Just in case some one didn't know this. Assign a float number to an integer<br>
> array element will always return integer.<br>
<br>
</div>right -- numpy arrays are typed -- that's one of the points of them --<br>
you wouldn't want the entire array up-cast with a single assignment --<br>
particularly since there are only python literals for a subset of the<br>
numpy types.<br>
<div class="im"><br>
> so I would always do this if I expected a transfer from integer to float?<br>
> In [18]: b=a.astype(float)<br>
<br>
</div>yes -- but that's an odd way of thinking about -- what you want to do<br>
is think about what type you need your array to be before you create<br>
it, then create it the way you need it:<br>
<br>
In [87]: np.arange(5, dtype=np.float)<br>
Out[87]: array([ 0.,  1.,  2.,  3.,  4.])<br>
<br>
or better:<br>
<br>
In [91]: np.linspace(0,5,6)<br>
Out[91]: array([ 0.,  1.,  2.,  3.,  4.,  5.])<br>
<br>
note that most (all?) numpy array constructors take a "dtype" argument.<br>
<br>
-Chris<br>
<div class="im"><br>
<br>
<br>
<br>
<br>
> In [19]: b<br>
> Out[19]: array([  2.,   4.,   6.,   8.,  10.])<br>
><br>
> In [20]: b[1]=4.5<br>
><br>
> In [21]: b<br>
> Out[21]: array([  2. ,   4.5,   6. ,   8. ,  10. ])<br>
><br>
> thanks et cheers,<br>
><br>
> Chao<br>
> --<br>
> ***********************************************************************************<br>
> Chao YUE<br>
> Laboratoire des Sciences du Climat et de l'Environnement (LSCE-IPSL)<br>
> UMR 1572 CEA-CNRS-UVSQ<br>
> Batiment 712 - Pe 119<br>
> 91191 GIF Sur YVETTE Cedex<br>
> Tel: (33) 01 69 08 29 02; Fax:01.69.08.77.16<br>
> ************************************************************************************<br>
><br>
><br>
</div>> _______________________________________________<br>
> NumPy-Discussion mailing list<br>
> <a href="mailto:NumPy-Discussion@scipy.org">NumPy-Discussion@scipy.org</a><br>
> <a href="http://mail.scipy.org/mailman/listinfo/numpy-discussion" target="_blank">http://mail.scipy.org/mailman/listinfo/numpy-discussion</a><br>
><br>
<br>
<br>
<br>
--<br>
<br>
Christopher Barker, Ph.D.<br>
Oceanographer<br>
<br>
Emergency Response Division<br>
NOAA/NOS/OR&R            (206) <a href="tel:526-6959" value="+485266959">526-6959</a>   voice<br>
7600 Sand Point Way NE   (206) <a href="tel:526-6329" value="+485266329">526-6329</a>   fax<br>
Seattle, WA  98115       (206) <a href="tel:526-6317" value="+485266317">526-6317</a>   main reception<br>
<br>
<a href="mailto:Chris.Barker@noaa.gov">Chris.Barker@noaa.gov</a><br>
_______________________________________________<br>
NumPy-Discussion mailing list<br>
<a href="mailto:NumPy-Discussion@scipy.org">NumPy-Discussion@scipy.org</a><br>
<a href="http://mail.scipy.org/mailman/listinfo/numpy-discussion" target="_blank">http://mail.scipy.org/mailman/listinfo/numpy-discussion</a><br>
</blockquote></div><br><br clear="all"><br>-- <br><div>***********************************************************************************</div>
<div>Chao YUE<br>Laboratoire des Sciences du Climat et de l'Environnement (LSCE-IPSL)<br>UMR 1572 CEA-CNRS-UVSQ<br>Batiment 712 - Pe 119<br>91191 GIF Sur YVETTE Cedex</div>
<div>Tel: (33) 01 69 08 29 02; Fax:01.69.08.77.16<br></div>

<div>************************************************************************************</div><br>