1

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.

1 Answer 1

2

It turns out the above example runs as expected when I updated Numpy to 1.16.0.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.