liveBook · Manning

Array

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

An array is an indexed, ordered collection of elements arranged in one or more dimensions, with elements accessed by position.

Arrays store fixed-size, same-type elements in a compact representation. Compared with lists, this can reduce per-element object overhead; lists trade extra allocated space for cheaper insertions. section 2.4.3

NumPy arrays extend this model to multiple dimensions. Reshaping or transposing can create views that share memory with the original array; shape and strides determine how positions map to that memory. section 4.0 section 4.1.2

m2x5 = linear.reshape((2, 5))
print(np.shares_memory(linear, m2x5))
 
print("2x5", m2x5.shape)
print("2x5 corners", m2x5[0, 0], m2x5[0, 4],
      m2x5[2, 0], m2x5[2, 4])
 
m5x2 = m2x5.T
print(np.shares_memory(m2x5, m5x2))
print("5x2", m5x2.shape)
print("5x2 corners", m5x2[0, 0], m5x2[0, 1],
      m5x2[4, 0], m5x2[4, 1])

Trace a one-dimensional array through reshape and transpose operations, checking shared memory and the resulting shapes. section 4.1.2

Doubling array elements

A simplified CPU/GPU model doubles 100 array elements: sequential CPU work is estimated at 18,200 time units, versus 240 for independent parallel threads under the stated assumptions. section 9.1.1

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

How deep it goes
Defines fixed-size, same-type storage and traces NumPy views through shared memory, shape, and strides; defers allocation details.
Examples
Demonstrates file bytes, reshaped and transposed NumPy views, and elementwise doubling.
What it assumes
Assumes some NumPy exposure for performance-focused treatment while introducing memory sharing and strides through examples.
What you can do after
Evaluate storage and execution trade-offs by comparing list overhead, shared-memory views, and sequential versus parallel array processing.
How it connects
Links arrays to Python lists, NumPy, memory layout, strides, and GPU computing.

Also explained in

Compare how 40 books explain array →

Related concepts

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.