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

Sturla Molden sturla@molden...
Tue Mar 24 08:13:57 CDT 2009


Jens Rantil wrote:
>
> 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?
Oops, my fault :)


def fromaddress(address, nbytes, dtype=float):
    class Dummy(object): pass
    d = Dummy()
    bytetype = numpy.dtype(numpy.uint8)
    d.__array_interface__ = {
         'data' : (address, False),
         'typestr' : bytetype.str,
         'descr' : bytetype.descr,
         'shape' : (nbytes,),
         'strides' : None,
         'version' : 3
    }   
    return numpy.asarray(d).view(dtype=dtype)


You will have to make sure the address is an integer.


> Also, could you elaborate why dtype=float would work better?
Because there is no such thing as a double type in Python?


Sturla Molden








More information about the Numpy-discussion mailing list