[Numpy-discussion] NumPy C-API equivalent of np.float64()
Wed Dec 29 13:53:35 CST 2010
On Wed, Dec 29, 2010 at 11:43 AM, Matthew Brett <email@example.com> wrote:
>>> 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
> while ago:
> Code in scipy here:
> See around line 36 there, and 432, and the header file I copied from
> Dag Sverre:
> 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...
Wow! That's a mouthful of code. Yes, very handy to have an example to
work from. Thank you.
More information about the NumPy-Discussion