Skip to content

Instantly share code, notes, and snippets.

@mattebb
mattebb / getArray.py
Last active December 10, 2015 13:28
Partio NumPy demo
import partio
import numpy as np
p = partio.create()
size = 3
posattr = p.addAttribute("pos",partio.FLOAT,size)
for i in range(8):
p.addParticle()
data = tuple(i+j*100 for j in range(size))
p.set(posattr, i, data)
@mattebb
mattebb / gist:4440528
Created January 3, 2013 03:29
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);