[Tutor] NumPy Question - numpy.put in multi-dimensional array

Bryan Fodness bryan.fodness at gmail.com
Wed Nov 14 01:57:23 CET 2007


Thank you.  That works great!

On Nov 13, 2007 7:18 PM, Eike Welk <eike.welk at gmx.net> wrote:
> Hello Bryan!
>
> On Wednesday 14 November 2007 00:18, Bryan Fodness wrote:
> > I see how to do it in a one-dimenstional array, but do not know the
> > syntax for the multi-dimensional case.
> >
> > >from numpy import *
> >
> > a = zeros((60,40), int)
> >
> > fields = {}
> > field = 10
> > fields[field] = '30A', 5
> >
> > iy = int(fields[field][1])
> > ix = int(fields[field][0].rstrip('AB'))
> >
> > for j in range(iy):
> >      put(a,[39 - j],[1])
> Should be maybe:
>       a[0, 39 - j] = 1
>
> >
> > Can someone help me figure out how I would do it for multiple rows?
> >
> > I thought,
> >
> > for i in range(ix):
> >    for j in range(iy):
> >         put(a,[i][39-j],[1])
> change to:
>          a[i, 39-j] = 1
>
> You could replace the nested for loops by the following code:
> a[:ix, :iy:-1] = 1
>
> I think you shouldn't use put(...) in your code. It is a fairly
> specialized function.
>
> More information:
> http://www.scipy.org/Numpy_Example_List_With_Doc#head-5202db3259f69441c695ab0efc0cdf45341829fc
>
> Regards,
> Eike
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>


More information about the Tutor mailing list