In [1]:
import numpy as np
In [2]:
a = np.arange(12).reshape(3, 4)
print(a.shape)
print(a)
In [3]:
print(np.sum(a))
In [4]:
print(np.sum(a, axis=0))
print(np.sum(a, axis=1))
In [5]:
print(a.sum())
In [6]:
print(a.sum(axis=0))
print(a.sum(axis=1))
In [7]:
print(np.mean(a))
In [8]:
print(np.mean(a, axis=0))
print(np.mean(a, axis=1))
In [9]:
print(a.mean())
In [10]:
print(a.mean(axis=0))
print(a.mean(axis=1))
In [11]:
print(np.min(a))
print(np.min(a, axis=0))
In [12]:
print(a.max())
print(a.max(axis=1))
In [13]:
b = np.arange(24).reshape(2, 3, 4)
print(b.shape)
print(b)
In [14]:
print(b.sum(axis=0))
In [15]:
print(b[0, :, :] + b[1, :, :])
In [16]:
print(b.sum(axis=1))
In [17]:
print(b[:, 0, :] + b[:, 1, :] + b[:, 2, :])
In [18]:
print(b.sum(axis=2))
In [19]:
print(b[:, :, 0] + b[:, :, 1] + b[:, :, 2] + b[:, :, 3])
In [20]:
print(b.sum(axis=(0, 1)))
In [21]:
print(b.sum(axis=(0, 2)))
In [22]:
print(b.sum(axis=(1, 2)))