<br><br><div><span class="gmail_quote">On 7/10/07, <b class="gmail_sendername">Mark.Miller</b> <<a href="mailto:mpmusu@cc.usu.edu">mpmusu@cc.usu.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;">
Just ran across something that doesn't quite make sense to me at the moment.<br><br>Here's some code:<br><br> >>> numpy.__version__<br>'1.0.2'<br> >>><br> >>> def f1(b,c):<br>        b=
b.astype(int)<br>        c=c.astype(int)<br>        return b,c<br><br> >>> b,c = numpy.fromfunction(f1,(5,5))<br> >>> a=numpy.zeros((2,12,5,5),int)<br> >>> a1=a[0]<br> >>> a1[:,b,c].shape
<br>(12, 5, 5)<br> >>> a[0,:,b,c].shape<br>(5, 5, 12)   ###why does this not return (12,5,5)?<br> >>><br><br>So in a nutshell, it's not completely clear to me why these are<br>returning arrays of different shapes.  Can someone shed some light?
</blockquote><div><br>It's because you are using arrays as indices (aka Fancy-Indexing). When you do this everything works differently. In this case, everything is being broadcast to the same shape. As I understand it (and I try to use only the simplest forms of fancy indexing), what you are doing is equivalent to:
<br></div></div><br>-- <br>.  __<br>.   |-\<br>.<br>.  <a href="mailto:tim.hochberg@ieee.org">tim.hochberg@ieee.org</a>