MCPcopy
hub / github.com/numpy/numpy / stack_arrays

Function stack_arrays

numpy/lib/recfunctions.py:1324–1408  ·  view source on GitHub ↗

Superposes arrays fields by fields Parameters ---------- arrays : array or sequence Sequence of input arrays. defaults : dictionary, optional Dictionary mapping field names to the corresponding default values. usemask : {True, False}, optional Whethe

(arrays, defaults=None, usemask=True, asrecarray=False,
                 autoconvert=False)

Source from the content-addressed store, hash-verified

1322
1323@array_function_dispatch(_stack_arrays_dispatcher)
1324def stack_arrays(arrays, defaults=None, usemask=True, asrecarray=False,
1325 autoconvert=False):
1326 """
1327 Superposes arrays fields by fields
1328
1329 Parameters
1330 ----------
1331 arrays : array or sequence
1332 Sequence of input arrays.
1333 defaults : dictionary, optional
1334 Dictionary mapping field names to the corresponding default values.
1335 usemask : {True, False}, optional
1336 Whether to return a MaskedArray (or MaskedRecords is
1337 `asrecarray==True`) or an ndarray.
1338 asrecarray : {False, True}, optional
1339 Whether to return a recarray (or MaskedRecords if `usemask==True`)
1340 or just a flexible-type ndarray.
1341 autoconvert : {False, True}, optional
1342 Whether automatically cast the type of the field to the maximum.
1343
1344 Examples
1345 --------
1346 >>> import numpy as np
1347 >>> from numpy.lib import recfunctions as rfn
1348 >>> x = np.array([1, 2,])
1349 >>> rfn.stack_arrays(x) is x
1350 True
1351 >>> z = np.array([('A', 1), ('B', 2)], dtype=[('A', '|S3'), ('B', float)])
1352 >>> zz = np.array([('a', 10., 100.), ('b', 20., 200.), ('c', 30., 300.)],
1353 ... dtype=[('A', '|S3'), ('B', np.double), ('C', np.double)])
1354 >>> test = rfn.stack_arrays((z,zz))
1355 >>> test
1356 masked_array(data=[(b'A', 1.0, --), (b'B', 2.0, --), (b'a', 10.0, 100.0),
1357 (b'b', 20.0, 200.0), (b'c', 30.0, 300.0)],
1358 mask=[(False, False, True), (False, False, True),
1359 (False, False, False), (False, False, False),
1360 (False, False, False)],
1361 fill_value=(b'N/A', 1e+20, 1e+20),
1362 dtype=[('A', 'S3'), ('B', '<f8'), ('C', '<f8')])
1363
1364 """
1365 if isinstance(arrays, np.ndarray):
1366 return arrays
1367 elif len(arrays) == 1:
1368 return arrays[0]
1369 seqarrays = [np.asanyarray(a).ravel() for a in arrays]
1370 nrecords = [len(a) for a in seqarrays]
1371 ndtype = [a.dtype for a in seqarrays]
1372 fldnames = [d.names for d in ndtype]
1373 #
1374 dtype_l = ndtype[0]
1375 newdescr = _get_fieldspec(dtype_l)
1376 names = [n for n, d in newdescr]
1377 for dtype_n in ndtype[1:]:
1378 for fname, fdtype in _get_fieldspec(dtype_n):
1379 if fname not in names:
1380 newdescr.append((fname, fdtype))
1381 names.append(fname)

Callers 8

test_soloMethod · 0.90
test_unnamed_fieldsMethod · 0.90
test_defaultsMethod · 0.90
test_autoconversionMethod · 0.90
test_checktitlesMethod · 0.90
test_subdtypeMethod · 0.90

Calls 8

_get_fieldspecFunction · 0.85
_fix_outputFunction · 0.85
_fix_defaultsFunction · 0.85
cumsumMethod · 0.80
maxFunction · 0.50
ravelMethod · 0.45
indexMethod · 0.45
sumMethod · 0.45

Tested by 8

test_soloMethod · 0.72
test_unnamed_fieldsMethod · 0.72
test_defaultsMethod · 0.72
test_autoconversionMethod · 0.72
test_checktitlesMethod · 0.72
test_subdtypeMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…