[Numpy-discussion] dtyping with .astype()

josef.pktd@gmai... josef.pktd@gmai...
Mon Oct 17 12:04:44 CDT 2011


On Mon, Oct 17, 2011 at 10:18 AM, Pauli Virtanen <pav@iki.fi> wrote:
> 17.10.2011 15:48, josef.pktd@gmail.com kirjoitti:
>> On Mon, Oct 17, 2011 at 6:17 AM, Pauli Virtanen <pav@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
>


More information about the NumPy-Discussion mailing list