Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

|, > and < in numpy datatype

Tags:

python

numpy

This could be a very silly question but I tried to google keywords like less and greater signs in data type of numpy and found no reference.

In the doc of numpy,

x = np.array([(1.0, 2), (3.0, 4)], dtype=[('x', float), ('y', int)])

outputs

array([(1.0, 2), (3.0, 4)],
      dtype=[('x', '<f8'), ('y', '<i4')])

But on my PC, the output is

array([(1.0, 2), (3.0, 4)],
      dtype=[('x', '>f8'), ('y', '>i4')])

What do < and > in the dtype mean and why there is the difference?

like image 329
ddzzbbwwmm Avatar asked Jul 04 '16 15:07

ddzzbbwwmm


People also ask

What is numpy Dtype (' O ')?

It means: 'O' (Python) objects. Source. The first character specifies the kind of data and the remaining characters specify the number of bytes per item, except for Unicode, where it is interpreted as the number of characters. The item size must correspond to an existing type, or an error will be raised.

What is float64 data type?

64 refers to the memory allocated to hold this character. Numeric characters with decimals. If a column contains numbers and NaNs(see below), pandas will default to float64, in case your missing value has a decimal. Values meant to hold time data.


1 Answers

The keywords < and > stand for byte ordering, aka endianness. It is the order in which bytes from numbers are stored (when numbers are compossed of more than 1 byte, e.g. int16, int32, float32...). This page from the reference gives you all the information you need about it in numpy, but as a summary:

  • | : it doesn't have a byte order because is redundant (on single byte numbers or strings)

  • < : little-endian

  • > : big-endian

As @tobias_k and @RobertKern pointed out, the default endianess, if not specified, is system dependant.

like image 157
Imanol Luengo Avatar answered Sep 18 '22 12:09

Imanol Luengo