How to Check If an NumPy Array Owns It’s Data Or Not


In this example we will show how to check if a NumPy array owns it’s data or not in Python.

Source Code

import numpy as np

n = np.array([1, 2, 3, 4])
copy_n = n.copy()
view_n = n.view()

# returns None if the array owns the data
print(copy_n.base)
print(view_n.base)

Output:

None
[1 2 3 4]
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments