Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python-numpy: Specifying item size of a compound data type doesn't work

Tags:

python

numpy

Am I doing something wrong here?

>>> import numpy as np
>>> dt = np.dtype({"names": ["First"], 
                   "formats": [np.uint32], 
                   "offsets": [3], 
                   "itemsize": 8})
>>> dt.itemsize
7
like image 690
dpitch40 Avatar asked May 03 '26 23:05

dpitch40


1 Answers

It looks like a bug to me. But if you just need n bytes of padding at the end a composite type may help:

import numpy as np
dt = np.dtype({"names": ["First", "_"], 
               "formats": [np.uint32, (np.void,1)], 
               "offsets": [3,7],
})
arr = np.empty( (5,), dtype=dt )
like image 129
dsign Avatar answered May 05 '26 11:05

dsign