[Numpy-discussion] NumPy C-API equivalent of np.float64()
matthew.brett at gmail.com
Wed Dec 29 14:43:22 EST 2010
>> That might be because I'm not understanding you very well, but I was
>> thinking that:
>> cdef dtype descr = PyArray_DescrFromType(NPY_FLOAT64)
>> would give you the float64 dtype that I thought you wanted? I'm
>> shooting from the hip here, in between nieces competing for the
>> computer and my attention.
> I think I need a function. One that does this:
>>> n = 10.0
>>> hasattr(n, 'ndim')
>>> m = np.float64(n)
>>> hasattr(m, 'ndim')
Now the nieces have gone, I see that I did completely misunderstand.
I think you want the C-API calls to be able to create a 0-dim ndarray
object from a python float.
There was a thread on C-API array creation on the cython list a little
Code in scipy here:
See around line 36 there, and 432, and the header file I copied from
As you can see, it's a little horrible, in that you have to take care
to get the references right to the dtype and to the data. I actually
did not investigate in detail whether this lower-level array creation
was speeding my code up much.
I hope that's more useful...
More information about the NumPy-Discussion