Thanks to the two of you!!<br><br>Chao<br><br><div class="gmail_quote">On Mon, Jun 3, 2013 at 11:53 AM, Sebastian Berg <span dir="ltr"><<a href="mailto:sebastian@sipsolutions.net" target="_blank">sebastian@sipsolutions.net</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">On Mon, 2013-06-03 at 10:44 +0200, Chao YUE wrote:<br>
> Dear all,<br>
><br>
> I have an array with 4 dim:<br>
><br>
> In [24]: dd.shape<br>
> Out[24]: (12, 13, 120, 170)<br>
><br>
> I would like to collapse the last two dim for applying np.sum(axis=-1)<br>
><br>
</div>If you use Numpy >= 1.7. you can also just use dd.sum(axis=(-1,-2))<br>
<span class="HOEnZb"><font color="#888888"><br>
- Sebastian<br>
</font></span><div class="im HOEnZb"><br>
<br>
> In [25]: dd.reshape(12,13,-1).shape<br>
> Out[25]: (12, 13, 20400)<br>
><br>
> is there a more general way to do this? something like<br>
> In [21]: dd.reshape(*dd.shape[0:2],-1).shape<br>
> ------------------------------------------------------------<br>
> File "<ipython console>", line 1<br>
> SyntaxError: only named arguments may follow *expression (<ipython<br>
> console>, line 1)<br>
><br>
> thanks a lot for any hints,<br>
><br>
> cheers,<br>
><br>
> Chao<br>
><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>
</div><div class="HOEnZb"><div class="h5">> _______________________________________________<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>
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>
</div></div></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>