@@ -69,12 +69,11 @@ def count_masked(arr, axis=None):
69
69
70
70
Examples
71
71
--------
72
- >>> import numpy.ma as ma
73
72
>>> a = np.arange(9).reshape((3,3))
74
- >>> a = ma.array(a)
75
- >>> a[1, 0] = ma.masked
76
- >>> a[1, 2] = ma.masked
77
- >>> a[2, 1] = ma.masked
73
+ >>> a = np. ma.array(a)
74
+ >>> a[1, 0] = np. ma.masked
75
+ >>> a[1, 2] = np. ma.masked
76
+ >>> a[2, 1] = np. ma.masked
78
77
>>> a
79
78
masked_array(
80
79
data=[[0, 1, 2],
@@ -84,14 +83,14 @@ def count_masked(arr, axis=None):
84
83
[ True, False, True],
85
84
[False, True, False]],
86
85
fill_value=999999)
87
- >>> ma.count_masked(a)
86
+ >>> np. ma.count_masked(a)
88
87
3
89
88
90
89
When the `axis` keyword is used an array is returned.
91
90
92
- >>> ma.count_masked(a, axis=0)
91
+ >>> np. ma.count_masked(a, axis=0)
93
92
array([1, 1, 1])
94
- >>> ma.count_masked(a, axis=1)
93
+ >>> np. ma.count_masked(a, axis=1)
95
94
array([0, 2, 1])
96
95
97
96
"""
@@ -124,8 +123,7 @@ def masked_all(shape, dtype=float):
124
123
125
124
Examples
126
125
--------
127
- >>> import numpy.ma as ma
128
- >>> ma.masked_all((3, 3))
126
+ >>> np.ma.masked_all((3, 3))
129
127
masked_array(
130
128
data=[[--, --, --],
131
129
[--, --, --],
@@ -138,10 +136,10 @@ def masked_all(shape, dtype=float):
138
136
139
137
The `dtype` parameter defines the underlying data type.
140
138
141
- >>> a = ma.masked_all((3, 3))
139
+ >>> a = np. ma.masked_all((3, 3))
142
140
>>> a.dtype
143
141
dtype('float64')
144
- >>> a = ma.masked_all((3, 3), dtype=np.int32)
142
+ >>> a = np. ma.masked_all((3, 3), dtype=np.int32)
145
143
>>> a.dtype
146
144
dtype('int32')
147
145
@@ -179,12 +177,11 @@ def masked_all_like(arr):
179
177
180
178
Examples
181
179
--------
182
- >>> import numpy.ma as ma
183
180
>>> arr = np.zeros((2, 3), dtype=np.float32)
184
181
>>> arr
185
182
array([[0., 0., 0.],
186
183
[0., 0., 0.]], dtype=float32)
187
- >>> ma.masked_all_like(arr)
184
+ >>> np. ma.masked_all_like(arr)
188
185
masked_array(
189
186
data=[[--, --, --],
190
187
[--, --, --]],
@@ -197,7 +194,7 @@ def masked_all_like(arr):
197
194
198
195
>>> arr.dtype
199
196
dtype('float32')
200
- >>> ma.masked_all_like(arr).dtype
197
+ >>> np. ma.masked_all_like(arr).dtype
F438
201
198
dtype('float32')
202
199
203
200
"""
@@ -839,6 +836,15 @@ def compress_nd(x, axis=None):
839
836
-------
840
837
compress_array : ndarray
841
838
The compressed array.
839
+
840
+ Examples
841
+ --------
842
+ >>> x = np.ma.array(np.arange(9).reshape(3, 3), mask=[[1, 0, 0],
843
+ ... [1, 0, 0],
844
+ ... [0, 0, 0]])
845
+ >>> np.ma.compress_nd(x)
846
+ array([[7, 8]])
847
+
842
848
"""
843
849
x = asarray (x )
844
850
m = getmask (x )
@@ -928,6 +934,14 @@ def compress_rows(a):
928
934
--------
929
935
compress_rowcols
930
936
937
+ Examples
938
+ --------
939
+ >>> a = np.ma.array(np.arange(9).reshape(3, 3), mask=[[1, 0, 0],
940
+ ... [1, 0, 0],
941
+ ... [0, 0, 0]])
942
+ >>> np.ma.compress_rows(a)
943
+ array([[6, 7, 8]])
944
+
931
945
"""
932
946
a = asarray (a )
933
947
if a .ndim != 2 :
@@ -946,6 +960,16 @@ def compress_cols(a):
946
960
--------
947
961
compress_rowcols
948
962
963
+ Examples
964
+ --------
965
+ >>> a = np.ma.array(np.arange(9).reshape(3, 3), mask=[[1, 0, 0],
966
+ ... [1, 0, 0],
967
+ ... [0, 0, 0]])
968
+ >>> np.ma.compress_cols(a)
969
+ array([[1, 2],
970
+ [4, 5],
971
+ [7, 8]])
972
+
949
973
"""
950
974
a = asarray (a )
951
975
if a .ndim != 2 :
@@ -998,14 +1022,13 @@ def mask_rowcols(a, axis=None):
998
1022
999
1023
Examples
1000
1024
--------
1001
- >>> import numpy.ma as ma
1002
1025
>>> a = np.zeros((3, 3), dtype=int)
1003
1026
>>> a[1, 1] = 1
1004
1027
>>> a
1005
1028
array([[0, 0, 0],
1006
1029
[0, 1, 0],
1007
1030
[0, 0, 0]])
1008
- >>> a = ma.masked_equal(a, 1)
1031
+ >>> a = np. ma.masked_equal(a, 1)
1009
1032
>>> a
1010
1033
masked_array(
1011
1034
data=[[0, 0, 0],
@@ -1015,7 +1038,7 @@ def mask_rowcols(a, axis=None):
1015
1038
[False, True, False],
1016
1039
[False, False, False]],
1017
1040
fill_value=1)
1018
- >>> ma.mask_rowcols(a)
1041
+ >>> np. ma.mask_rowcols(a)
1019
1042
masked_array(
1020
1043
data=[[0, --, 0],
1021
1044
[--, --, --],
@@ -1055,14 +1078,13 @@ def mask_rows(a, axis=np._NoValue):
1055
1078
1056
1079
Examples
1057
1080
--------
1058
- >>> import numpy.ma as ma
1059
1081
>>> a = np.zeros((3, 3), dtype=int)
1060
1082
>>> a[1, 1] = 1
1061
1083
>>> a
1062
1084
array([[0, 0, 0],
1063
1085
[0, 1, 0],
1064
1086
[0, 0, 0]])
1065
- >>> a = ma.masked_equal(a, 1)
1087
+ >>> a = np. ma.masked_equal(a, 1)
1066
1088
>>> a
1067
1089
masked_array(
1068
1090
data=[[0, 0, 0],
@@ -1073,7 +1095,7 @@ def mask_rows(a, axis=np._NoValue):
1073
1095
[False, False, False]],
1074
1096
fill_value=1)
1075
1097
1076
- >>> ma.mask_rows(a)
1098
+ >>> np. ma.mask_rows(a)
1077
1099
masked_array(
1078
1100
data=[[0, 0, 0],
1079
1101
[--, --, --],
@@ -1106,14 +1128,13 @@ def mask_cols(a, axis=np._NoValue):
1106
1128
1107
1129
Examples
1108
1130
--------
1109
- >>> import numpy.ma as ma
1110
1131
>>> a = np.zeros((3, 3), dtype=int)
1111
1132
>>> a[1, 1] = 1
1112
1133
>>> a
1113
1134
array([[0, 0, 0],
1114
1135
[0, 1, 0],
1115
1136
[0, 0, 0]])
1116
- >>> a = ma.masked_equal(a, 1)
1137
+ >>> a = np. ma.masked_equal(a, 1)
1117
1138
>>> a
1118
1139
masked_array(
1119
1140
data=[[0, 0, 0],
@@ -1123,7 +1144,7 @@ def mask_cols(a, axis=np._NoValue):
1123
1144
[False, True, False],
1124
1145
[False, False, False]],
1125
1146
fill_value=1)
1126
- >>> ma.mask_cols(a)
1147
+ >>> np. ma.mask_cols(a)
1127
1148
masked_array(
1128
1149
data=[[0, --, 0],
1129
1150
[0, --, 0],
@@ -1158,6 +1179,14 @@ def ediff1d(arr, to_end=None, to_begin=None):
1158
1179
--------
1159
1180
numpy.ediff1d : Equivalent function for ndarrays.
1160
1181
1182
+ Examples
1183
+ --------
1184
+ >>> arr = np.ma.array([1, 2, 4, 7, 0])
1185
+ >>> np.ma.ediff1d(arr)
1186
+ masked_array(data=[ 1, 2, 3, -7],
1187
+ mask=False,
1188
+ fill_value=999999)
1189
+
F438
1161
1190
"""
1162
1191
arr = ma .asanyarray (arr ).flat
1163
1192
ed = arr [1 :] - arr [:- 1 ]
@@ -1189,27 +1218,26 @@ def unique(ar1, return_index=False, return_inverse=False):
1189
1218
1190
1219
Examples
1191
1220
--------
1192
- >>> import numpy.ma as ma
1193
1221
>>> a = [1, 2, 1000, 2, 3]
1194
1222
>>> mask = [0, 0, 1, 0, 0]
1195
- >>> masked_a = ma.masked_array(a, mask)
1223
+ >>> masked_a = np. ma.masked_array(a, mask)
1196
1224
>>> masked_a
1197
1225
masked_array(data=[1, 2, --, 2, 3],
1198
1226
mask=[False, False, True, False, False],
1199
1227
fill_value=999999)
1200
- >>> ma.unique(masked_a)
1228
+ >>> np. ma.unique(masked_a)
1201
1229
masked_array(data=[1, 2, 3, --],
1202
1230
mask=[False, False, False, True],
1203
1231
fill_value=999999)
1204
- >>> ma.unique(masked_a, return_index=True)
1232
+ >>> np. ma.unique(masked_a, return_index=True)
1205
1233
(masked_array(data=[1, 2, 3, --],
1206
1234
mask=[False, False, False, True],
1207
1235
fill_value=999999), array([0, 1, 4, 2]))
1208
- >>> ma.unique(masked_a, return_inverse=True)
1236
+ >>> np. ma.unique(masked_a, return_inverse=True)
1209
1237
(masked_array(data=[1, 2, 3, --],
1210
1238
mask=[False, False, False, True],
1211
1239
fill_value=999999), array([0, 1, 3, 1, 2]))
1212
- >>> ma.unique(masked_a, return_index=True, return_inverse=True)
1240
+ >>> np. ma.unique(masked_a, return_index=True, return_inverse=True)
1213
1241
(masked_array(data=[1, 2, 3, --],
1214
1242
mask=[False, False, False, True],
1215
1243
fill_value=999999), array([0, 1, 4, 2]), array([0, 1, 3, 1, 2]))
@@ -1268,6 +1296,15 @@ def setxor1d(ar1, ar2, assume_unique=False):
1268
1296
--------
1269
1297
numpy.setxor1d : Equivalent function for ndarrays.
1270
1298
1299
+ Examples
1300
+ --------
1301
+ >>> ar1 = np.ma.array([1, 2, 3, 2, 4])
1302
+ >>> ar2 = np.ma.array([2, 3, 5, 7, 5])
1303
+ >>> np.ma.setxor1d(ar1, ar2)
1304
+ masked_array(data=[1, 4, 5, 7],
1305
+ mask=False,
1306
+ fill_value=999999)
1307
+
1271
1308
"""
1272
1309
if not assume_unique :
1273
1310
ar1 = unique (ar1 )
@@ -1303,6 +1340,15 @@ def in1d(ar1, ar2, assume_unique=False, invert=False):
1303
1340
-----
1304
1341
.. versionadded:: 1.4.0
1305
1342
1343
+ Examples
1344
+ --------
1345
+ >>> ar1 = np.ma.array([0, 1, 2, 5, 0])
1346
+ >>> ar2 = [0, 2]
1347
+ >>> np.ma.in1d(ar1, ar2)
1348
+ masked_array(data=[ True, False, True, False, True],
1349
+ mask=False,
1350
+ fill_value=True)
1351
+
1306
1352
"""
1307
1353
if not assume_unique :
1308
1354
ar1 , rev_idx = unique (ar1 , return_inverse = True )
@@ -1344,6 +1390,15 @@ def isin(element, test_elements, assume_unique=False, invert=False):
1344
1390
-----
1345
1391
.. versionadded:: 1.13.0
1346
1392
1393
+ Examples
1394
+ --------
1395
+ >>> element = np.ma.array([1, 2, 3, 4, 5, 6])
1396
+ >>> test_elements = [0, 2]
1397
+ >>> np.ma.isin(element, test_elements)
1398
+ masked_array(data=[False, True, False, False, False, False],
1399
+ mask=False,
1400
+ fill_value=True)
1401
+
1347
1402
"""
1348
1403
element = ma .asarray (element )
1349
1404
return in1d (element , test_elements , assume_unique = assume_unique ,
@@ -1360,6 +1415,15 @@ def union1d(ar1, ar2):
1360
1415
--------
1361
1416
numpy.union1d : Equivalent function for ndarrays.
1362
1417
1418
+ Examples
1419
+ --------
1420
+ >>> ar1 = np.ma.array([1, 2, 3, 4])
1421
+ >>> ar2 = np.ma.array([3, 4, 5, 6])
1422
+ >>> np.ma.union1d(ar1, ar2)
1423
+ masked_array(data=[1, 2, 3, 4, 5, 6],
1424
+ mask=False,
1425
+ fill_value=999999)
1426
+
1363
1427
"""
1364
1428
return unique (ma .concatenate ((ar1 , ar2 ), axis = None ))
1365
1429
@@ -1492,6 +1556,23 @@ def cov(x, y=None, rowvar=True, bias=False, allow_masked=True, ddof=None):
1492
1556
--------
1493
1557
numpy.cov
1494
1558
1559
+ Examples
1560
+ --------
1561
+ >>> x = np.ma.array([[0, 1], [1, 1]], mask=[0, 1, 0, 1])
1562
+ >>> y = np.ma.array([[1, 0], [0, 1]], mask=[0, 0, 1, 1])
1563
+ >>> np.ma.cov(x, y)
1564
+ masked_array(
1565
+ data=[[--, --, --, --],
1566
+ [--, --, --, --],
1567
+ [--, --, --, --],
1568
+ [--, --, --, --]],
1569
+ mask=[[ True, True, True, True],
1570
+ [ True, True, True, True],
1571
+ [ True, True, True, True],
1572
+ [ True, True, True, True]],
1573
+ fill_value=1e+20,
1574
+ dtype=float64)
1575
+
1495
1576
"""
1496
1577
# Check inputs
1497
1578
if ddof is not None and ddof != int (ddof ):
@@ -1560,6 +1641,19 @@ def corrcoef(x, y=None, rowvar=True, bias=np._NoValue, allow_masked=True,
1560
1641
for backwards compatibility with previous versions of this function. These
1561
1642
arguments had no effect on the return values of the function and can be
1562
1643
safely ignored in this and previous versions of numpy.
1644
+
1645
+ Examples
1646
+ --------
1647
+ >>> x = np.ma.array([[0, 1], [1, 1]], mask=[0, 1, 0, 1])
1648
+ >>> np.ma.corrcoef(x)
1649
+ masked_array(
1650
+ data=[[--, --],
1651
+ [--, --]],
1652
+ mask=[[ True, True],
1653
+ [ True, True]],
1654
+ fill_value=1e+20,
1655
+ dtype=float64)
1656
+
1563
1657
"""
1564
1658
msg = 'bias and ddof have no effect and are deprecated'
1565
1659
if bias is not np ._NoValue or ddof is not np ._NoValue :
0 commit comments