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)
| 7093 | |
| 7094 | |
| 7095 | def concatenate(arrays, axis=0): |
| 7096 | """ |
| 7097 | Concatenate a sequence of arrays along the given axis. |
| 7098 | |
| 7099 | Parameters |
| 7100 | ---------- |
| 7101 | arrays : sequence of array_like |
| 7102 | The arrays must have the same shape, except in the dimension |
| 7103 | corresponding to `axis` (the first, by default). |
| 7104 | axis : int, optional |
| 7105 | The axis along which the arrays will be joined. Default is 0. |
| 7106 | |
| 7107 | Returns |
| 7108 | ------- |
| 7109 | result : MaskedArray |
| 7110 | The concatenated array with any masked entries preserved. |
| 7111 | |
| 7112 | See Also |
| 7113 | -------- |
| 7114 | numpy.concatenate : Equivalent function in the top-level NumPy module. |
| 7115 | |
| 7116 | Examples |
| 7117 | -------- |
| 7118 | >>> import numpy.ma as ma |
| 7119 | >>> a = ma.arange(3) |
| 7120 | >>> a[1] = ma.masked |
| 7121 | >>> b = ma.arange(2, 5) |
| 7122 | >>> a |
| 7123 | masked_array(data=[0, --, 2], |
| 7124 | mask=[False, True, False], |
| 7125 | fill_value=999999) |
| 7126 | >>> b |
| 7127 | masked_array(data=[2, 3, 4], |
| 7128 | mask=False, |
| 7129 | fill_value=999999) |
| 7130 | >>> ma.concatenate([a, b]) |
| 7131 | masked_array(data=[0, --, 2, 2, 3, 4], |
| 7132 | mask=[False, True, False, False, False, False], |
| 7133 | fill_value=999999) |
| 7134 | |
| 7135 | """ |
| 7136 | d = np.concatenate([getdata(a) for a in arrays], axis) |
| 7137 | rcls = get_masked_subclass(*arrays) |
| 7138 | data = d.view(rcls) |
| 7139 | # Check whether one of the arrays has a non-empty mask. |
| 7140 | for x in arrays: |
| 7141 | if getmask(x) is not nomask: |
| 7142 | break |
| 7143 | else: |
| 7144 | return data |
| 7145 | # OK, so we have to concatenate the masks |
| 7146 | dm = np.concatenate([getmaskarray(a) for a in arrays], axis) |
| 7147 | dm = dm.reshape(d.shape) |
| 7148 | |
| 7149 | # If we decide to keep a '_shrinkmask' option, we want to check that |
| 7150 | # all of them are True, and then check for dm.any() |
| 7151 | data._mask = _shrink_mask(dm) |
| 7152 | return data |