Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specifying NumPy Arrays with 2-Bit Dtype

According to the docs, it's possible to specify different array dtypes:

dt = np.dtype('u1')   # 8-bit unsigned integer
dt = np.dtype('i4')   # 32-bit signed integer
dt = np.dtype('f8')   # 64-bit floating-point number
dt = np.dtype('c16')  # 128-bit complex floating-point number
dt = np.dtype('a25')  # 25-length zero-terminated bytes
dt = np.dtype('U25')  # 25-character string

However, the smallest unsigned integer dtype is 8-bit. Is there a way to create a 2-bit unsigned integer dtype?

like image 928
slaw Avatar asked Jan 01 '19 22:01

slaw


People also ask

Can NumPy arrays contain multiple data types?

Can an array store different data types? Yes, a numpy array can store different data String, Integer, Complex, Float, Boolean.

How do I change the Dtype of a NumPy array?

In order to change the dtype of the given array object, we will use numpy. astype() function. The function takes an argument which is the target data type. The function supports all the generic types and built-in types of data.

Do NumPy arrays have to have the same data type?

NumPy arrays have a fixed number of elements and all the elements have the same datatype, both specified when creating the array.

Can NumPy hold different data types?

Data Types in NumPyNumPy has some extra data types, and refer to data types with one character, like i for integers, u for unsigned integers etc. Below is a list of all data types in NumPy and the characters used to represent them.


1 Answers

According to the NumPy mailing list from November 2009, NumPy has 1-byte atomicity and so a 8-bit is the smallest unit. Even bool dtype uses a single byte.

like image 78
slaw Avatar answered Sep 30 '22 18:09

slaw