Scalar Types
NumPy provides a rich set of scalar types that correspond to fixed-size memory representations of numbers and other data. These types are the building blocks of NumPy arrays.Type Hierarchy
All NumPy scalar types inherit fromnumpy.generic. The hierarchy enables type checking and ensures consistent behavior:
numpy.generic- Base class for all scalar typesnumpy.number- Base for all numeric typesnumpy.integer- Base for all integer typesnumpy.floating- Base for floating-point typesnumpy.complexfloating- Base for complex types
numpy.flexible- Base for strings and voidnumpy.bool_- Boolean typenumpy.object_- Python object type
Boolean Type
bool_
Boolean type (True or False), stored as a byte.'?'
Integers
NumPy provides both signed and unsigned integers in various sizes.Signed Integers
int8 (byte)
int8 (byte)
8-bit signed integer: -128 to 127Character code:
'b'
Aliases: numpy.byteint16 (short)
int16 (short)
16-bit signed integer: -32,768 to 32,767Character code:
'h'
Aliases: numpy.shortint32 (intc)
int32 (intc)
32-bit signed integer: -2,147,483,648 to 2,147,483,647Character code:
'i'
Aliases: numpy.intc (C int)int64 (long, int_)
int64 (long, int_)
64-bit signed integer: -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807Character code:
'l' or 'q'
Aliases: numpy.long, numpy.int_ (default integer on 64-bit systems)Unsigned Integers
uint8 (ubyte)
uint8 (ubyte)
8-bit unsigned integer: 0 to 255Character code:
'B'
Aliases: numpy.ubyte
Common use: Image pixel values, byte datauint16 (ushort)
uint16 (ushort)
16-bit unsigned integer: 0 to 65,535Character code:
'H'
Aliases: numpy.ushortuint32 (uintc)
uint32 (uintc)
32-bit unsigned integer: 0 to 4,294,967,295Character code:
'I'
Aliases: numpy.uintcuint64 (ulong, uint)
uint64 (ulong, uint)
64-bit unsigned integer: 0 to 18,446,744,073,709,551,615Character code:
'L' or 'Q'
Aliases: numpy.ulong, numpy.uintPlatform-Dependent Integers
- intp: Integer used for indexing (same as C
ssize_t, typically int64) - uintp: Unsigned integer for indexing (same as C
size_t)
Floating-Point Types
Floating-point types follow IEEE 754 standard.float16 (half)
Half precision float: 16-bit (1 sign, 5 exponent, 10 mantissa)'e'
Range: ~±6.55e4
Precision: ~3-4 decimal digits
Use case: ML inference, memory-constrained applications
float32 (single)
Single precision float: 32-bit (1 sign, 8 exponent, 23 mantissa)'f'
Aliases: numpy.single
Range: ~±3.4e38
Precision: ~7-8 decimal digits
Use case: Graphics, ML training, scientific computing when memory matters
float64 (double)
Double precision float: 64-bit (1 sign, 11 exponent, 52 mantissa)'d'
Aliases: numpy.double, numpy.float_ (default)
Range: ~±1.8e308
Precision: ~15-16 decimal digits
Use case: Default for most scientific computing
float96, float128 (longdouble)
Extended precision float (platform dependent)'g'
Aliases: numpy.longdouble
Note: Size varies by platform (often 80-bit or 128-bit)
Complex Types
Complex numbers consist of two floating-point numbers (real and imaginary parts).complex64 (csingle)
Complex number with 2x float32'F'
Aliases: numpy.csingle
Size: 64 bits (32 bits each for real and imaginary)
complex128 (cdouble)
Complex number with 2x float64'D'
Aliases: numpy.cdouble, numpy.complex_ (default)
Size: 128 bits (64 bits each for real and imaginary)
complex192, complex256 (clongdouble)
Extended precision complex (platform dependent)'G'
Aliases: numpy.clongdouble
String Types
str_ (unicode)
Unicode string (UCS-4 encoding)'U'
Note: Size is specified in characters, not bytes
bytes_
Byte string (fixed-length)'S'
Note: Size is in bytes
Other Types
object_
Arbitrary Python object'O'
Warning: Operations are slower, no vectorization benefits
void
Raw data (unstructured)'V'
Use case: Raw byte buffers, custom structured types
datetime64
Date and time type'M'
Units: Y, M, W, D, h, m, s, ms, us, ns, ps, fs, as
timedelta64
Time duration type'm' (lowercase)
Units: Same as datetime64
Type Relationships
Type Hierarchy Checks
Type Promotion
Examples
Choosing Appropriate Type
Memory Efficiency
Type Checking in Functions
Common Pitfalls
See Also
- dtype Overview - Overview of dtype system
- Character Codes - Type string codes
- NumPy Data Types
- NumPy Scalars
