liveBook · Manning

Base

As explained in Fast Python: High performance techniques for large datasets

base is a NumPy array attribute referencing the first array object in the chain from which a view derives.

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

How Fast Python: High performance techniques for large datasets covers it

How deep it goes
Defines the direct ownership reference and demonstrates identity checks, but does not detail deeper ownership-chain behavior.
Examples
Uses a grayscale image, vertical flips, base comparisons, and np.shares_memory checks.
What it assumes
Assumes familiarity with NumPy arrays and introduces views, copies, and memory sharing through image-processing operations.
What you can do after
Diagnose whether array transformations preserve shared storage or allocate independent data.
How it connects
Connects arrays with views, copies, shared memory, and NumPy array ownership.

This explainer was generated by Manning's knowledge graph from the text of Fast Python: High performance techniques for large datasets. The section links point to the parts of the book it draws on.