base is a NumPy array attribute that references the first array object in the chain from which a view derives. It exposes ownership relationships behind shared-memory arrays. section 4.1.1
Use base to distinguish views from independent copies:
- A view created by np.flipud(image_arr) has image_arr as its base. section 4.1.1
- A copied result has base set to None because it owns separate data. section 4.1.1
- Use identity comparison, such as flipped_from_view.base is image_arr, to test the direct relationship. section 4.1.1
Checking an image flip
After loading the grayscale logo into image_arr, compare flipped_from_copy.base with flipped_from_view.base. The copy prints None, while the view references image_arr; np.shares_memory provides a separate memory-sharing check. section 4.1.1
print(flipped_from_copy.base, flipped_from_view.base) print(flipped_from_view.base is image_arr) #1 print(flipped_from_view.base == image_arr) #2
Inspect the base values and identity comparison used to distinguish the copied and viewed arrays. section 4.1.1
