Posts

Showing posts from February 8, 2019

numpy 2d int array to C array of int pointers using ctypes

Image
0 I have a function in C that accepts a nxm integer matrix as an array of n int pointers. Each pointer points to the first element of an integer array of size m, so they these arrays can be seen as the rows of the matrix. So for example: void func(int **matrix, int n, int m); And in memory, the array looks like array 1 from this page: http://c-faq.com/aryptr/dynmuldimary.html I want to use this C function from within Python using ctypes. So I imported it and gave it the following argtypes: func.argtypes = [ctypes.POINTER(ctypes.POINTER(ctypes.c_int)), ctypes.c_int, ctypes.c_int] Now I want to give the function a numpy 2d array... Lets say I have a 2d numpy int array: a = np.random.rand(2,3) * 100 a = a.astype("int") How can I convert the numpy matrix a to the proper format and vice ...

Getting index of minimum distance in Panda's dataframe

Image
1 The head of my data as follows: lat1 long1 state county lat2 long2 dist Depot 0 . . AK Aleutians West 11.0 23.0 121 0.0 1 . . AK Wade Hampton 33.0 11.0 12 0.0 2 . . AK North Slope 55.0 11.0 43 0.0 3 . . AK Kenai Peninsula 44.0 11.0 43 0.0 4 . . AK Anchorage 11.0 11.0 99 0.0 5 1 2 AK Anchorage NaN NaN 1e10 0.0 6 . . AK Anchorage 55.0 44.0 33 0.0 7 3 4 AK Anchorage NaN NaN 1e10 0.0 8 . . AK Anchorage 3.0 2.0 23 0.0 9 . . AK Anchorage 5.0 11.0 32 0.0 10 . . AK Anchorage 42.0 22.0 33 0.0 11 . . AK Anchor...