On Tue, Mar 16, 2010 at 8:47 AM, Sam Tygier
<[email protected]> wrote:
> Hello
>
> I can't find much documentation for using arrays where the dtype has named 
> fields (is there a term for this sort of array). there is some in
> http://docs.scipy.org/doc/numpy/reference/arrays.dtypes.html
> http://docs.scipy.org/doc/numpy/reference/generated/numpy.dtype.html
> but that's most creation.

structured arrays, or structured dtypes (similar to recarrays but simpler)

http://docs.scipy.org/doc/numpy/user/basics.rec.html
http://www.scipy.org/Cookbook/Recarray

the best information, I think, is on the mailing list, search for
structured array

e.g. slicing is not possible, slicing requires a view as regular ndarray

there are some slightly hidden (because still work in progress) helper functions
>>> import numpy.lib.recfunctions
>>> dir(numpy.lib.recfunctions)

Josef

>
> for example if i have
> a = zeros(5, dtype=[('a','f'), ('b','f'), ('c','i')])
> and fill it with values.
>
> if i want to fill a row, i can do
> a[0] = (0.1,0.2,3)
> but if i use a list it wont work
> a[0] = [0.1,0.2,3]
> is there an explanation of why?
>
> now if i wanted to do some sort of conversion, eg multiply columns 'a' and 
> 'b' by 10, is there a way to do
> a *= [10,10,1]
> like i would do with a if were a zeros((5,3)) array
> is
> a['a'] *= 10
> a['b'] *= 10
> the best method?
>
> also whats the best way to take a slice of the columns? if i want just the 
> 'a' and 'b' columns. if it were a 2d array i could do
> a[0:2]
> but
> a['a':'b']
> does not work. is there a way to do this?
>
> thanks
>
> Sam
> _______________________________________________
> NumPy-Discussion mailing list
> [email protected]
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
_______________________________________________
NumPy-Discussion mailing list
[email protected]
http://mail.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to