
Everyone, Shouldn't the itemsize below be 2?
import numpy as np dtype = np.dtype( [ (((2,), 'top'), [('nested', 'i1')]) ] ) dtype.itemsize 1 np.__version__ '1.0.4'
The elements of the dtype are of type array of size 2. Each element is a (nested) record array of size 2 with one field of type 'i1'. In contiguous memory, this should look identical to an 'i1' array of size 2. -Igor Sylvester

A simpler example returns 1 as well: np.dtype( [ (((2,), 'a'), 'i1') ] ).itemsize On Tue, Jan 6, 2009 at 2:07 PM, Igor Sylvester <igorsyl@gmail.com> wrote:
Everyone,
Shouldn't the itemsize below be 2?
import numpy as np dtype = np.dtype( [ (((2,), 'top'), [('nested', 'i1')]) ] ) dtype.itemsize 1 np.__version__ '1.0.4'
The elements of the dtype are of type array of size 2. Each element is a (nested) record array of size 2 with one field of type 'i1'. In contiguous memory, this should look identical to an 'i1' array of size 2.
-Igor Sylvester

On Tue, Jan 6, 2009 at 14:07, Igor Sylvester <igorsyl@gmail.com> wrote:
Everyone,
Shouldn't the itemsize below be 2?
import numpy as np dtype = np.dtype( [ (((2,), 'top'), [('nested', 'i1')]) ] ) dtype.itemsize 1 np.__version__ '1.0.4'
The elements of the dtype are of type array of size 2. Each element is a (nested) record array of size 2 with one field of type 'i1'. In contiguous memory, this should look identical to an 'i1' array of size 2.
That's not a valid dtype. Array fields should be of the form (name, subdtype, shape), not ((shape, name), subdtype). I'm not sure why dtype() does not simply reject this input. In [22]: np.dtype([('top', [('nested', 'i1')], (2,))]).itemsize Out[22]: 2 -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco

If array fields should be of the form (name,subdtype, shape), how do I specify field offsets? My datatype is word-aligned. Thanks. On Tue, Jan 6, 2009 at 3:41 PM, Robert Kern <robert.kern@gmail.com> wrote:
On Tue, Jan 6, 2009 at 14:07, Igor Sylvester <igorsyl@gmail.com> wrote:
Everyone,
Shouldn't the itemsize below be 2?
import numpy as np dtype = np.dtype( [ (((2,), 'top'), [('nested', 'i1')]) ] ) dtype.itemsize 1 np.__version__ '1.0.4'
The elements of the dtype are of type array of size 2. Each element is a (nested) record array of size 2 with one field of type 'i1'. In contiguous memory, this should look identical to an 'i1' array of size 2.
That's not a valid dtype. Array fields should be of the form (name, subdtype, shape), not ((shape, name), subdtype). I'm not sure why dtype() does not simply reject this input.
In [22]: np.dtype([('top', [('nested', 'i1')], (2,))]).itemsize Out[22]: 2
-- Robert Kern
"I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco _______________________________________________ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion

On Tue, Jan 6, 2009 at 22:04, Igor Sylvester <igorsyl@gmail.com> wrote:
If array fields should be of the form (name,subdtype, shape), how do I specify field offsets? My datatype is word-aligned.
With dtype(some_list), you need to explicitly include the padding. E.g. ('', '|V4') to add 4 bytes of padding. Alternately, you can use dtype(some_dict): dtype(dict( names=['x', 'y'], formats=['u1', ('u1', (2,2))], offsets=[0, 4], )) -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco
participants (2)
-
Igor Sylvester
-
Robert Kern