</>
Topic 3 of 3
Theory

Matrices

An array can be two-dimensional — a matrix. shape shows its size, axis says which direction to compute along:

m = np.array([[1, 2, 3],
              [4, 5, 6]])
print(m.shape)          # (2, 3)
print(m.T)              # transpose: rows ↔ columns
print(m.sum(axis=0))    # by column: [5 7 9]
print(m.sum(axis=1))    # by row: [ 6 15]
print(np.zeros((2, 2)))

Flip the table

Easy+10 XP

Return the transposed matrix: rows become columns.

transpose([[1, 2], [3, 4]]) → [[1, 3], [2, 4]]
main.pyLoading Python, numpy…
Output
Press "Check" to run the tests