Jason S
Jason S

Reputation: 189686

query properties of numpy dtypes

I have a program which uses at runtime some numpy datatypes e.g. uint8, int8, uint16, int16, uint32, int32.

Is there a way at run time to query these datatype objects and determine the following properties?

Upvotes: 1

Views: 148

Answers (1)

tom10
tom10

Reputation: 69192

For ints you could use iinfo to get part of the way to what you want:

d = np.dtype('int8')  # for example

min_value = np.iinfo(d).min
max_value = np.iinfo(d).max
signed = min_value!=0   # can also use "dtype.kind", see Jaime's comment
size = d.itemsize       # see comment

Upvotes: 2

Related Questions