Skip to content

Instantly share code, notes, and snippets.

@mattebb
Created January 3, 2013 03:29
Show Gist options
  • Save mattebb/4440528 to your computer and use it in GitHub Desktop.
Save mattebb/4440528 to your computer and use it in GitHub Desktop.
Numpy C-API bits
/* ensure array is contiguous, aligned and correct data type */
array = PyArray_FROM_OTF(input_array, NPY_FLOAT32, NPY_CARRAY_RO);
/* reshape the input array to the correct dimensions */
PyArray_Dims dims;
npy_intp shape[2] = {-1, attr.count};
dims.len = 2;
dims.ptr = shape;
array = PyArray_Newshape((PyArrayObject *)array, &dims, NPY_CORDER);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment