Closed elnazazmi closed 3 years ago
Getting a Fortran pointer to the data of a numpy array can fail for various reasons. For multidimensional arrays storage order is an additional complication.
Here is a summary of these problems and possible solutions: https://github.com/ylikx/forpy/wiki/Working-with-arrays#accessing-array-elements-with-ndarrayget_data
You can insert a call err_print
statement to check what the problem is with your matrix.
Thank you for your reply, it was very helpful. As you also mentioned, my error was the numpy array storage order which was in 'C' order. With
ierror = arr%get_data(matrix, order='C')
everything is fine. I should only know that the result is the transpose of the array.
I could create a 1d Fortran matrix from a 1d numpy array using:
ierror = numpy_array%get_data(fortran_matrix)
but, when I try to do the same for a 2d matrix I get an ierror = -1 with no result returned. Is there another function for doing this?