Matlab numerictype/reinterpretcast equivalent in python?

后端 未结 2 1487
暖寄归人
暖寄归人 2021-01-18 00:07

In Matlab there is a command to define a new numeric type for example:

numerictype(0,16,8) 

see documentation: https://www.mathworks.com/help

2条回答
  •  一整个雨季
    2021-01-18 00:20

    You could use np.dtype. I used your representation of your dtype in the following snippet:

    import numpy as np
    dtype=[('signed', np.bool_), ('word', np.int16), ('frac', np.int16)] 
    mytype = np.dtype(dtype)
    

    and you can use it in an array like so:

    np.array([True,1,1],dtype=mytype)
    

提交回复
热议问题