Return a description for the given data type code in Python

To return a description for the given data type code, use the typename() method in Python NumPy. This method provides human-readable descriptions for NumPy data type codes, making it easier to understand what each code represents.

Syntax

numpy.typename(char)

Parameters

char ? The data type code (single character string) for which you want the description.

Return Value

Returns a string describing the data type corresponding to the given type code.

Example

First, import the required library ?

import numpy as np

# Array of common NumPy data type codes
type_codes = ['S1', '?', 'B', 'D', 'G', 'F', 'I', 'H', 'L', 'O', 'Q', 'S', 'U', 'V', 'b', 'd', 'g', 'f', 'i', 'h', 'l', 'q']

# Get description for each data type code
for code in type_codes:
    print(f"{code} : {np.typename(code)}")
S1 : character
? : bool
B : unsigned char
D : complex double precision
G : complex long double precision
F : complex single precision
I : unsigned integer
H : unsigned short
L : unsigned long integer
O : object
Q : unsigned long long integer
S : string
U : unicode
V : void
b : signed char
d : double precision
g : long precision
f : single precision
i : integer
h : short
l : long integer
q : long long integer

Common Data Type Codes

Code Description Category
i, h, l, q Signed integers Integer
I, H, L, Q Unsigned integers Integer
f, d, g Floating point Float
F, D, G Complex numbers Complex
S, U String/Unicode String
? Boolean Boolean

Conclusion

The np.typename() method is useful for understanding NumPy data type codes. It helps in debugging and data type verification by providing clear descriptions for single-character type codes used throughout NumPy.

Updated on: 2026-03-26T19:16:35+05:30

279 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements