[Numpy-discussion] how to work with numpy.int8 in c
Christopher Barker
Chris.Barker@noaa....
Tue Mar 2 19:06:07 CST 2010
Warren Weckesser wrote:
>>>> I want to create one of those numpy.int8 guys.
>>>>
>> np.int8 is a type, and so is numpy.ndarray. And they are different.
>> There's lots of docs about how to make arrays, but how do I make a
>> scalar?
ah - I see -- you want to make a numpy scalar, not the same as a type,
actually.
Numpy scalars exist because numpy supports data types that core python
does not have, so they are a lot like the built-in float and integer
scalars.
I'm still curious as to why you might need to make one, usually, C code
works with numpy arrays, and you can easily make an array that has one
element:
In [83]: np.array(4, dtype=np.uint8)
Out[83]: array(4, dtype=uint8)
(In python). Usually, you have no arrays in C, and but work with the
scalars as regular old C types.
If you do really need to create a numpy scalar is C, it looks like you
can use:
PyArrayScalar(void* data, PyArray_Descr* dtype, PyObject* itemsize)
I found this in "The Guide to Numpy":
http://www.tramy.us/guidetoscipy.html
HTH,
-Chris
--
Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker@noaa.gov
More information about the NumPy-Discussion
mailing list