Matt
Matt

Reputation: 826

How to convert from a NumPy data type to a custom data type?

I have defined a new numeric data type in Python using Python's Data Model. I would like to convert all my existing NumPy arrays from their existing data types to my custom data type. I understand that NumPy's astype method converts from one data type to another, but based on my understanding, it can only convert between built-in data types.

In contrast to the answer provided here, my data type is not based on built-in data types and has it's own addition, multiplication, bit-wise operations, etc., so I cannot use np.dtype to define my data type. In other words, the following solution would not work:

kerneldt = np.dtype([('myintname', np.int32), ('myfloats', np.float64, 9)])
arr = np.empty(dims, dtype=kerneldt)

Is there any way to convert between a built-in data type and a custom data type and vice versa?

Upvotes: 0

Views: 469

Answers (1)

ngoldbaum
ngoldbaum

Reputation: 5580

This isn't currently possible. There are plans to allow custom dtypes in numpy in the future.

Upvotes: 1

Related Questions