2 # This example demonstrates how to access the internals
3 # of a Numeric array object.
6 cdef extern from "Numeric/arrayobject.h":
12 ctypedef class Numeric.ArrayType [object PyArrayObject]:
15 cdef int *dimensions, *strides
17 cdef PyArray_Descr *descr
20 def print_2d_array(ArrayType a):
21 print "Type:", chr(a.descr.type)
22 if chr(a.descr.type) <> "f":
23 raise TypeError("Float array required")
25 raise ValueError("2 dimensional array required")
28 nrows = a.dimensions[0]
29 ncols = a.dimensions[1]
30 elems = <float *>a.data
32 divider = ("+" + 10 * hyphen) * ncols + "+"
34 for row in range(nrows):
35 for col in range(ncols):
36 x = elems[row * ncols + col]