How to pass a Numpy array into a cffi function and how to get one back out?

The ctypes attribute of ndarray can interact with the ctypes module, for example, ndarray.ctypes.data is the data address of the array, you can cast it to a float * pointer, and then pass the pointer to the C function. import numpy as np from cffi import FFI ffi = FFI() ffi.cdef(“void copy(float *in, float *out, … Read more

ipython: how to set terminal width

You can see your current line width with numpy.get_printoptions()[‘linewidth’] and set it with numpy.set_printoptions(linewidth=160) Automatically set printing width If you’d like the terminal width to be set automatically, you can have Python execute a startup script. So create a file ~/.python_startup.py or whatever you want to call it, with this inside it: # Set the … Read more

Speedup scipy griddata for multiple interpolations between two irregular grids

There are several things going on every time you make a call to scipy.interpolate.griddata: First, a call to sp.spatial.qhull.Delaunay is made to triangulate the irregular grid coordinates. Then, for each point in the new grid, the triangulation is searched to find in which triangle (actually, in which simplex, which in your 3D case will be … Read more

How to sort 2D array (numpy.ndarray) based to the second column in python? [duplicate]

Use .argsort() it returns an numpy.array of indices that sort the given numpy.array. You call it as a function or as a method on your array. For example, suppose you have import numpy as np arr = np.array([[-0.30565392, -0.96605562], [ 0.85331367, -2.62963495], [ 0.87839643, -0.28283675], [ 0.72676698, 0.93213482], [-0.52007354, 0.27752806], [-0.08701666, 0.22764316], [-1.78897817, 0.50737573], [ … Read more

How can I create a slice object for Numpy array?

Yes you can use numpy.s_: Example: >>> a = np.arange(10).reshape(2, 5) >>> >>> m = np.s_[0:2, 3:4] >>> >>> a[m] array([[3], [8]]) And in this case: my_slice = np.s_[cpix[1]-50:cpix[1]+50, cpix[0]-50:cpix[0]+50] a1 = array1[my_slice] a2 = array2[my_slice] a3 = array3[my_slice] You can also use numpy.r_ in order to translates slice objects to concatenation along the first … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)