MCPcopy Create free account
hub / github.com/numpy/numpy / concatenate

Function concatenate

numpy/ma/core.py:7095–7152  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

7093
7094
7095def 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

Callers 15

test_testUfuncs1Method · 0.90
test_testAddSumProdMethod · 0.90
test_testCopySizeMethod · 0.90
test_copyMethod · 0.90
test_addsumprodMethod · 0.90
original_fftshiftMethod · 0.90
original_ifftshiftMethod · 0.90
appendFunction · 0.70
_from_stringFunction · 0.50

Calls 7

getdataFunction · 0.85
get_masked_subclassFunction · 0.85
getmaskFunction · 0.85
getmaskarrayFunction · 0.85
_shrink_maskFunction · 0.85
reshapeMethod · 0.80
viewMethod · 0.45

Tested by 10

test_testUfuncs1Method · 0.72
test_testAddSumProdMethod · 0.72
test_testCopySizeMethod · 0.72
test_copyMethod · 0.72
test_addsumprodMethod · 0.72
original_fftshiftMethod · 0.72
original_ifftshiftMethod · 0.72