On Jun 3, 2009, at 5:03 PM, Robert Kern wrote:
> On Wed, Jun 3, 2009 at 15:26, <[email protected]> wrote:
>> 2009/6/3 Stéfan van der Walt <[email protected]>:
>>> Hi Jon
>>>
>>> 2009/6/3 D2Hitman <[email protected]>:
>>>> I understand record arrays such as:
>>>> a_array =
>>>> np.array([(0.,1.,2.,3.,4.),(1.,2.,3.,4.,5.)],dtype=[('a','f'),
>>>> ('b','f'),('c','f'),('d','f'),('e','f')])
>>>> do this with field names.
>>>> a_array['a'] = array([ 0., 1.], dtype=float32)
>>>> however i seem to lose simple operations such as multiplication
>>>> (a_array*2)
>>>> or powers (a_array**2).
>> Why does it not preserve "shape", to do e.g. np.mean by axis?
>
> It does preserve the shape. The input and output are both 1D. If you
> need a different shape (e.g. re-interpreting the record as another
> axis), you need to reshape it yourself. numpy can't guess what you
> want.
Or, as all fields have the same dtype:
>>> a_array.view(dtype=('f',len(a_array.dtype)))
array([[ 0., 1., 2., 3., 4.],
[ 1., 2., 3., 4., 5.]], dtype=float32)
Ain't it fun ?
_______________________________________________
Numpy-discussion mailing list
[email protected]
http://mail.scipy.org/mailman/listinfo/numpy-discussion