import numpy as np
ridership = np.array([
[ 0, 0, 2, 5, 0],
[1478, 3877, 3674, 2328, 2539],
[1613, 4088, 3991, 6461, 2691],
[1560, 3392, 3826, 4787, 2613],
[1608, 4802, 3932, 4477, 2705],
[1576, 3933, 3909, 4979, 2685],
[ 95, 229, 255, 496, 201],
[ 2, 0, 1, 27, 0],
[1438, 3785, 3589, 4174, 2215],
[1342, 4043, 4009, 4665, 3033]
])
print ridership[1, 3]
2328
print ridership[1:3, 3:5]
[[2328 2539]
[6461 2691]]
print ridership[1, :]
[1478 3877 3674 2328 2539]
[取行,取列]
print ridership[0, :] + ridership[1, :]
[1478 3877 3676 2333 2539]
print ridership[:, 0] + ridership[:, 1]
[ 0 5355 5701 4952 6410 5509 324 2 5223 5385]
a = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
b = np.array([[1, 1, 1], [2, 2, 2], [3, 3, 3]])
print a + b
[[ 2 3 4]
[ 6 7 8]
[10 11 12]]
a = np.array([
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
])
print a.sum()
print a.sum(axis=0)
print a.sum(axis=1)
45
[12 15 18]
[ 6 15 24]