I am getting an unexpected result with two Numpy arrays when I represent them as Ctypes pointers. I have created a minimal example that reproduces the problem I am running into:
import numpy as np
from ctypes import c_float, POINTER
c_float_p = POINTER(c_float)
a = np.array([1], dtype=c_float).ctypes.data_as(c_float_p)
b = np.array([2], dtype=c_float).ctypes.data_as(c_float_p)
print('a: {}, b: {}'.format(a.contents, b.contents))
When I run this I get the following output:
a: c_float(2.0), b: c_float(2.0)
Clearly the contents of the first array have been overridden with the contents of the second. Hence, it seems that the two pointers point to the same location. How can I avoid this from happening?
Note: I am using Python 3.6, Numpy 1.15.4.