Concatenate a sequence of arrays along the given axis. Parameters ---------- arrays : sequence of array_like The arrays must have the same shape, except in the dimension corresponding to `axis` (the first, by default). axis : int, optional The axis along
(arrays, axis=0)
| 7312 | |
| 7313 | |
| 7314 | def concatenate(arrays, axis=0): |
| 7315 | """ |
| 7316 | Concatenate a sequence of arrays along the given axis. |
| 7317 | |
| 7318 | Parameters |
| 7319 | ---------- |
| 7320 | arrays : sequence of array_like |
| 7321 | The arrays must have the same shape, except in the dimension |
| 7322 | corresponding to `axis` (the first, by default). |
| 7323 | axis : int, optional |
| 7324 | The axis along which the arrays will be joined. Default is 0. |
| 7325 | |
| 7326 | Returns |
| 7327 | ------- |
| 7328 | result : MaskedArray |
| 7329 | The concatenated array with any masked entries preserved. |
| 7330 | |
| 7331 | See Also |
| 7332 | -------- |
| 7333 | numpy.concatenate : Equivalent function in the top-level NumPy module. |
| 7334 | |
| 7335 | Examples |
| 7336 | -------- |
| 7337 | >>> import numpy as np |
| 7338 | >>> import numpy.ma as ma |
| 7339 | >>> a = ma.arange(3) |
| 7340 | >>> a[1] = ma.masked |
| 7341 | >>> b = ma.arange(2, 5) |
| 7342 | >>> a |
| 7343 | masked_array(data=[0, --, 2], |
| 7344 | mask=[False, True, False], |
| 7345 | fill_value=999999) |
| 7346 | >>> b |
| 7347 | masked_array(data=[2, 3, 4], |
| 7348 | mask=False, |
| 7349 | fill_value=999999) |
| 7350 | >>> ma.concatenate([a, b]) |
| 7351 | masked_array(data=[0, --, 2, 2, 3, 4], |
| 7352 | mask=[False, True, False, False, False, False], |
| 7353 | fill_value=999999) |
| 7354 | |
| 7355 | """ |
| 7356 | d = np.concatenate([getdata(a) for a in arrays], axis) |
| 7357 | rcls = get_masked_subclass(*arrays) |
| 7358 | data = d.view(rcls) |
| 7359 | # Check whether one of the arrays has a non-empty mask. |
| 7360 | for x in arrays: |
| 7361 | if getmask(x) is not nomask: |
| 7362 | break |
| 7363 | else: |
| 7364 | return data |
| 7365 | # OK, so we have to concatenate the masks |
| 7366 | dm = np.concatenate([getmaskarray(a) for a in arrays], axis) |
| 7367 | dm = dm.reshape(d.shape) |
| 7368 | |
| 7369 | # If we decide to keep a '_shrinkmask' option, we want to check that |
| 7370 | # all of them are True, and then check for dm.any() |
| 7371 | data._mask = _shrink_mask(dm) |
searching dependent graphs…