Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- cimport numpy as np
- np.import_array()
- from libc.stdlib cimport malloc, calloc, free
- from cpython.ref cimport PyTypeObject
- from python_ref cimport Py_INCREF
- cdef extern from "<numpy/arrayobject.h>":
- object PyArray_NewFromDescr(PyTypeObject *subtype, np.dtype descr,int nd, np.npy_intp* dims,
- np.npy_intp*strides,void* data, int flags, object obj)
- def stackarr():
- cdef np.npy_intp dims[2]
- #cdef np.npy_intp strides[2]
- #cdef char *data
- #data = <char *>calloc(100, sizeof(char))
- cdef float *data
- data = <float *>calloc(100, sizeof(float))
- cdef np.dtype dtype = np.dtype('<f')
- Py_INCREF(dtype)
- dims[0] = 10
- dims[1] = 10
- #strides[0] = 1
- #strides[1] = 10
- for i in range(10):
- for j in range(10):
- data[i * 10 + j] = i * 10 + j
- ret = PyArray_NewFromDescr(<PyTypeObject *> np.ndarray, np.dtype('<f'), 2,
- dims, NULL,data, np.NPY_C_CONTIGUOUS, None)
- return ret
- print "Successfully imported"
Add Comment
Please, Sign In to add comment