[Numpy-discussion] numpy.ctypeslib.ndpointer and the restype attribute

Jens Rantil jens.rantil@telia....
Tue Mar 24 05:10:42 CDT 2009


On Mon, 2009-03-23 at 15:40 +0100, Sturla Molden wrote:
> def fromaddress(address, nbytes, dtype=double):
>     class Dummy(object): pass
>     d = Dummy()
>     d.__array_interface__ = {
>          'data' : (address, False),
>          'typestr' : numpy.uint8.str,
>          'descr' : numpy.uint8.descr,
>          'shape' : (nbytes,),
>          'strides' : None,
>          'version' : 3
>     }   
> 
>     return numpy.asarray(d).view( dtype=dtype )

Thanks Sturla. However numpy.uint8 seem to be lacking attributes 'str'
and 'descr'. I'm using installed Ubuntu package 1:1.1.1-1. Is it too old
or is the code broken?

Also, could you elaborate why dtype=float would work better?

Jens



More information about the Numpy-discussion mailing list