[Numpy-discussion] dtyping with .astype()

2011-10-17 Thread Alex van der Spek
Beginner's question?

I have this dictionary dtypes of names and types:

dtypes
{'names': ['col1', 'col2', 'col3', 'col4', 'col5'], 'formats': [type 
'numpy.float16', type 'numpy.float16', type 'numpy.float16', type 
'numpy.float16', type 'numpy.float16']}

and this array y

 y
array([[ 0,  1,  2,  3,  4],
   [ 5,  6,  7,  8,  9],
   [10, 11, 12, 13, 14],
   [15, 16, 17, 18, 19],
   [20, 21, 22, 23, 24],
   [25, 26, 27, 28, 29],
   [30, 31, 32, 33, 34],
   [35, 36, 37, 38, 39],
   [40, 41, 42, 43, 44],
   [45, 46, 47, 48, 49]])


But:
z=y.astype(dtypes)

gives me a confusing result. I only asked to name the columns and change their 
types to half precision floats.

What am I missing? How to do this?

Thank you in advance, 
Alex van der Spek

___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] dtyping with .astype()

2011-10-17 Thread Pauli Virtanen
13.10.2011 12:59, Alex van der Spek kirjoitti:
 gives me a confusing result. I only asked to name the columns and change 
 their 
 types to half precision floats.

Structured arrays shouldn't be thought as an array with named columns,
as they are somewhat different.

 What am I missing? How to do this?

np.rec.fromarrays(arr.T, dtype=dt)

___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] dtyping with .astype()

2011-10-17 Thread josef . pktd
On Mon, Oct 17, 2011 at 6:17 AM, Pauli Virtanen p...@iki.fi wrote:
 13.10.2011 12:59, Alex van der Spek kirjoitti:
 gives me a confusing result. I only asked to name the columns and change 
 their
 types to half precision floats.

 Structured arrays shouldn't be thought as an array with named columns,
 as they are somewhat different.

 What am I missing? How to do this?

 np.rec.fromarrays(arr.T, dtype=dt)

y.astype(float16).view(dt)

?
Josef



 ___
 NumPy-Discussion mailing list
 NumPy-Discussion@scipy.org
 http://mail.scipy.org/mailman/listinfo/numpy-discussion

___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] dtyping with .astype()

2011-10-17 Thread Pauli Virtanen
17.10.2011 15:48, josef.p...@gmail.com kirjoitti:
 On Mon, Oct 17, 2011 at 6:17 AM, Pauli Virtanen p...@iki.fi wrote:
[clip]
 What am I missing? How to do this?

 np.rec.fromarrays(arr.T, dtype=dt)
 
 y.astype(float16).view(dt)

I think this will give surprises if the original array is not in C-order.

Pauli

___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] dtyping with .astype()

2011-10-17 Thread josef . pktd
On Mon, Oct 17, 2011 at 10:18 AM, Pauli Virtanen p...@iki.fi wrote:
 17.10.2011 15:48, josef.p...@gmail.com kirjoitti:
 On Mon, Oct 17, 2011 at 6:17 AM, Pauli Virtanen p...@iki.fi wrote:
 [clip]
 What am I missing? How to do this?

 np.rec.fromarrays(arr.T, dtype=dt)

 y.astype(float16).view(dt)

 I think this will give surprises if the original array is not in C-order.

I forgot about those, dangerous if the array is square, otherwise it
raises an error if it is in F-order

maybe
np.asarray(y, np.float16, order='C').view(dt)
if I don't like record arrays

Josef


        Pauli

 ___
 NumPy-Discussion mailing list
 NumPy-Discussion@scipy.org
 http://mail.scipy.org/mailman/listinfo/numpy-discussion

___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion