Empty masked array with the properties of an existing array. Return an empty masked array of the same shape and dtype as the array `arr`, where all the data are masked. Parameters ---------- arr : ndarray An array describing the shape and dtype of the required Mask
(arr)
| 179 | |
| 180 | |
| 181 | def masked_all_like(arr): |
| 182 | """ |
| 183 | Empty masked array with the properties of an existing array. |
| 184 | |
| 185 | Return an empty masked array of the same shape and dtype as |
| 186 | the array `arr`, where all the data are masked. |
| 187 | |
| 188 | Parameters |
| 189 | ---------- |
| 190 | arr : ndarray |
| 191 | An array describing the shape and dtype of the required MaskedArray. |
| 192 | |
| 193 | Returns |
| 194 | ------- |
| 195 | a : MaskedArray |
| 196 | A masked array with all data masked. |
| 197 | |
| 198 | Raises |
| 199 | ------ |
| 200 | AttributeError |
| 201 | If `arr` doesn't have a shape attribute (i.e. not an ndarray) |
| 202 | |
| 203 | See Also |
| 204 | -------- |
| 205 | masked_all : Empty masked array with all elements masked. |
| 206 | |
| 207 | Notes |
| 208 | ----- |
| 209 | Unlike other masked array creation functions (e.g. `numpy.ma.zeros_like`, |
| 210 | `numpy.ma.ones_like`, `numpy.ma.full_like`), `masked_all_like` does not |
| 211 | initialize the values of the array, and may therefore be marginally |
| 212 | faster. However, the values stored in the newly allocated array are |
| 213 | arbitrary. For reproducible behavior, be sure to set each element of the |
| 214 | array before reading. |
| 215 | |
| 216 | Examples |
| 217 | -------- |
| 218 | >>> import numpy as np |
| 219 | >>> arr = np.zeros((2, 3), dtype=np.float32) |
| 220 | >>> arr |
| 221 | array([[0., 0., 0.], |
| 222 | [0., 0., 0.]], dtype=float32) |
| 223 | >>> np.ma.masked_all_like(arr) |
| 224 | masked_array( |
| 225 | data=[[--, --, --], |
| 226 | [--, --, --]], |
| 227 | mask=[[ True, True, True], |
| 228 | [ True, True, True]], |
| 229 | fill_value=np.float64(1e+20), |
| 230 | dtype=float32) |
| 231 | |
| 232 | The dtype of the masked array matches the dtype of `arr`. |
| 233 | |
| 234 | >>> arr.dtype |
| 235 | dtype('float32') |
| 236 | >>> np.ma.masked_all_like(arr).dtype |
| 237 | dtype('float32') |
| 238 |
searching dependent graphs…