-
import numpy as np
-
-
a = np.arange(
12).reshape(
3,
4)
-
print('a:', a)
-
print('np.where(a >
5):', np.where(a >
5))
-
print('a[np.where(a >
5)]:', a[np.where(a >
5)])
-
print('np.where(a >
5)[
0]:', np.where(a >
5)[
0])
-
print('np.where(a >
5)[
1]:', np.where(a >
5)[
1])
-
print(a[np.where(a >
5)[
0], np.where(a >
5)[
1]])
-
a: [[
0
1
2
3]
-
[
4
5
6
7]
-
[
8
9
10
11]]
-
np.where(a >
5): (array([
1,
1,
2,
2,
2,
2]), array([
2,
3,
0,
1,
2,
3]))
-
a[np.where(a >
5)]: [
6
7
8
9
10
11]
-
np.where(a >
5)[
0]: [
1
1
2
2
2
2]
-
np.where(a >
5)[
1]: [
2
3
0
1
2
3]
-
[
6
7
8
9
10
11]
np.where()[0] 表示行索引,np.where()[1]表示列索引