[Numpy-discussion] how to work with numpy.int8 in c
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
ah - I see -- you want to make a numpy scalar, not the same as a type,
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
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
In : np.array(4, dtype=np.uint8)
Out: 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
PyArrayScalar(void* data, PyArray_Descr* dtype, PyObject* itemsize)
I found this in "The Guide to Numpy":
Christopher Barker, Ph.D.
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
More information about the NumPy-Discussion