From: Sebastian H. <ha...@ms...> - 2006-08-18 18:26:16
|
Hi, array dtype descriptors have an attribute itemsize that gives the total number of bytes required for an item of that dtype. Scalar types, like numy.int32, also have that attribute, but it returns "something else" - don't know what: >>> a.dtype.itemsize 4 >>> a.dtype.name 'float32' >>> N.int32.itemsize <attribute 'itemsize' of 'genericscalar' objects> Furthermore there are *lot's* of more attributes to a scalar dtype, e.g. >>> N.int32.data <attribute 'data' of 'genericscalar' objects> >>> N.int32.argmax() Traceback (most recent call last): File "<input>", line 1, in ? TypeError: descriptor 'argmax' of 'genericscalar' object needs an argument Are those useful ? Thanks, Sebastian Haase |
From: Travis O. <oli...@ie...> - 2006-08-18 18:38:37
|
Sebastian Haase wrote: > Hi, > array dtype descriptors have an attribute itemsize that gives the total > number of bytes required for an item of that dtype. > > Scalar types, like numy.int32, also have that attribute, > but it returns "something else" - don't know what: > > > Furthermore there are *lot's* of more attributes to a scalar dtype, e.g. > The scalar types are actual Python types (classes) whereas the dtype objects are instances. The attributes you are seeing of the typeobject are very useful when you have an instance of that type. With numpy.int32.itemsize you are doing the equivalent of numpy.dtype.itemsize -Travis |
From: Sebastian H. <ha...@ms...> - 2006-08-18 20:16:18
|
On Friday 18 August 2006 11:38, Travis Oliphant wrote: > Sebastian Haase wrote: > > Hi, > > array dtype descriptors have an attribute itemsize that gives the total > > number of bytes required for an item of that dtype. > > > > Scalar types, like numy.int32, also have that attribute, > > but it returns "something else" - don't know what: > > > > > > Furthermore there are *lot's* of more attributes to a scalar dtype, e.g. > > The scalar types are actual Python types (classes) whereas the dtype > objects are instances. > > The attributes you are seeing of the typeobject are very useful when you > have an instance of that type. > > With numpy.int32.itemsize you are doing the equivalent of > numpy.dtype.itemsize but why then do I not get the result 4 ? -Sebastian |
From: Sebastian H. <ha...@ms...> - 2006-08-18 22:57:25
|
On Friday 18 August 2006 15:25, Travis Oliphant wrote: > Sebastian Haase wrote: > > On Friday 18 August 2006 11:38, Travis Oliphant wrote: > >> Sebastian Haase wrote: > >>> Hi, > >>> array dtype descriptors have an attribute itemsize that gives the > >>> total number of bytes required for an item of that dtype. > >>> > >>> Scalar types, like numy.int32, also have that attribute, > >>> but it returns "something else" - don't know what: > >>> > >>> > >>> Furthermore there are *lot's* of more attributes to a scalar dtype, > >>> e.g. > >> > >> The scalar types are actual Python types (classes) whereas the dtype > >> objects are instances. > >> > >> The attributes you are seeing of the typeobject are very useful when you > >> have an instance of that type. > >> > >> With numpy.int32.itemsize you are doing the equivalent of > >> numpy.dtype.itemsize > > > > but why then do I not get the result 4 ? > > Because it's not a "class" attribute, it's an instance attribute. > > What does numpy.dtype.itemsize give you? > I'm really sorry for being so dumb - but HOW can I get then the number of bytes needed by a given scalar type ? -S. |
From: Travis O. <oli...@ie...> - 2006-08-18 22:26:03
|
Sebastian Haase wrote: > On Friday 18 August 2006 11:38, Travis Oliphant wrote: > >> Sebastian Haase wrote: >> >>> Hi, >>> array dtype descriptors have an attribute itemsize that gives the total >>> number of bytes required for an item of that dtype. >>> >>> Scalar types, like numy.int32, also have that attribute, >>> but it returns "something else" - don't know what: >>> >>> >>> Furthermore there are *lot's* of more attributes to a scalar dtype, e.g. >>> >> The scalar types are actual Python types (classes) whereas the dtype >> objects are instances. >> >> The attributes you are seeing of the typeobject are very useful when you >> have an instance of that type. >> >> With numpy.int32.itemsize you are doing the equivalent of >> numpy.dtype.itemsize >> > > but why then do I not get the result 4 ? > Because it's not a "class" attribute, it's an instance attribute. What does numpy.dtype.itemsize give you? -Travis |
From: Travis O. <oli...@ie...> - 2006-08-18 23:51:50
|
Sebastian Haase wrote: > On Friday 18 August 2006 15:25, Travis Oliphant wrote: > >> Sebastian Haase wrote: >> >>> On Friday 18 August 2006 11:38, Travis Oliphant wrote: >>> >>>> Sebastian Haase wrote: >>>> >>>>> Hi, >>>>> array dtype descriptors have an attribute itemsize that gives the >>>>> total number of bytes required for an item of that dtype. >>>>> >>>>> Scalar types, like numy.int32, also have that attribute, >>>>> but it returns "something else" - don't know what: >>>>> >>>>> >>>>> Furthermore there are *lot's* of more attributes to a scalar dtype, >>>>> e.g. >>>>> >>>> The scalar types are actual Python types (classes) whereas the dtype >>>> objects are instances. >>>> >>>> The attributes you are seeing of the typeobject are very useful when you >>>> have an instance of that type. >>>> >>>> With numpy.int32.itemsize you are doing the equivalent of >>>> numpy.dtype.itemsize >>>> >>> but why then do I not get the result 4 ? >>> >> Because it's not a "class" attribute, it's an instance attribute. >> >> What does numpy.dtype.itemsize give you? >> >> > I'm really sorry for being so dumb - but HOW can I get then the number of > bytes needed by a given scalar type ? > > Ah, the real question. Sorry for not catching it earlier. I've been in "make sure this isn't a bug mode" for a long time. If you have a scalar type you could create one and then check the itemsize: int32(0).itemsize Or you could look at the name and parse out how big it is. There is also a stored dictionary-like object that returns the number of bytes for any data-type recognized: numpy.nbytes[int32] -Travis |
From: Sebastian H. <ha...@ms...> - 2006-08-19 00:05:24
|
On Friday 18 August 2006 16:51, Travis Oliphant wrote: > Sebastian Haase wrote: > > On Friday 18 August 2006 15:25, Travis Oliphant wrote: > >> Sebastian Haase wrote: > >>> On Friday 18 August 2006 11:38, Travis Oliphant wrote: > >>>> Sebastian Haase wrote: > >>>>> Hi, > >>>>> array dtype descriptors have an attribute itemsize that gives the > >>>>> total number of bytes required for an item of that dtype. > >>>>> > >>>>> Scalar types, like numy.int32, also have that attribute, > >>>>> but it returns "something else" - don't know what: > >>>>> > >>>>> > >>>>> Furthermore there are *lot's* of more attributes to a scalar dtype, > >>>>> e.g. > >>>> > >>>> The scalar types are actual Python types (classes) whereas the dtype > >>>> objects are instances. > >>>> > >>>> The attributes you are seeing of the typeobject are very useful when > >>>> you have an instance of that type. > >>>> > >>>> With numpy.int32.itemsize you are doing the equivalent of > >>>> numpy.dtype.itemsize > >>> > >>> but why then do I not get the result 4 ? > >> > >> Because it's not a "class" attribute, it's an instance attribute. > >> > >> What does numpy.dtype.itemsize give you? > > > > I'm really sorry for being so dumb - but HOW can I get then the number of > > bytes needed by a given scalar type ? > > Ah, the real question. Sorry for not catching it earlier. I've been in > "make sure this isn't a bug mode" for a long time. > > If you have a scalar type you could create one and then check the itemsize: > > int32(0).itemsize > > Or you could look at the name and parse out how big it is. > > There is also a stored dictionary-like object that returns the number of > bytes for any data-type recognized: > > numpy.nbytes[int32] Thanks, that seems to be a handy "dictionary-like object" Just for the record - in the meantime I found this: >>> N.dtype(N.int32).itemsize 4 Cheers, Sebastian |
From: Charles R H. <cha...@gm...> - 2006-08-27 02:03:50
|
Hi, On 8/18/06, Sebastian Haase <ha...@ms...> wrote: <snip> Thanks, that seems to be a handy "dictionary-like object" > > Just for the record - in the meantime I found this: > >>> N.dtype(N.int32).itemsize > 4 And on x86_64 linux python ints are 8 bytes. In [15]: asarray([1])[0].itemsize Out[15]: 8 Interesting. Looks like one needs to be careful about the builtin python types. Chuck |