Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """ Problem with Numpy dtypes in a Python dict """
- import numpy as np
- # dict for conversion from unsigned to signed
- typesDict = {np.uint8: np.int8,
- np.uint16: np.int16,
- np.uint32: np.int32,
- np.uint64: np.int64}
- # array of unsigned type
- aU = np.array([1, 2, 3], dtype=np.uint16)
- dtypeU = aU.dtype
- # make sure array is of unsigned type
- assert dtypeU == np.uint16
- # get the corresponding signed type
- dtypeS = typesDict.get(dtypeU, None)
- print("dtype: {} => {}".format(dtypeU, dtypeS)) # expected: uint16 => int16
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement