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

Function merge_arrays

numpy/lib/recfunctions.py:364–497  ·  view source on GitHub ↗

Merge arrays field by field. Parameters ---------- seqarrays : sequence of ndarrays Sequence of arrays fill_value : {float}, optional Filling value used to pad missing data on the shorter arrays. flatten : {False, True}, optional Whether to collapse

(seqarrays, fill_value=-1, flatten=False,
                 usemask=False, asrecarray=False)

Source from the content-addressed store, hash-verified

362
363@array_function_dispatch(_merge_arrays_dispatcher)
364def merge_arrays(seqarrays, fill_value=-1, flatten=False,
365 usemask=False, asrecarray=False):
366 """
367 Merge arrays field by field.
368
369 Parameters
370 ----------
371 seqarrays : sequence of ndarrays
372 Sequence of arrays
373 fill_value : {float}, optional
374 Filling value used to pad missing data on the shorter arrays.
375 flatten : {False, True}, optional
376 Whether to collapse nested fields.
377 usemask : {False, True}, optional
378 Whether to return a masked array or not.
379 asrecarray : {False, True}, optional
380 Whether to return a recarray (MaskedRecords) or not.
381
382 Examples
383 --------
384 >>> import numpy as np
385 >>> from numpy.lib import recfunctions as rfn
386 >>> rfn.merge_arrays((np.array([1, 2]), np.array([10., 20., 30.])))
387 array([( 1, 10.), ( 2, 20.), (-1, 30.)],
388 dtype=[('f0', '<i8'), ('f1', '<f8')])
389
390 >>> rfn.merge_arrays((np.array([1, 2], dtype=np.int64),
391 ... np.array([10., 20., 30.])), usemask=False)
392 array([(1, 10.0), (2, 20.0), (-1, 30.0)],
393 dtype=[('f0', '<i8'), ('f1', '<f8')])
394 >>> rfn.merge_arrays((np.array([1, 2]).view([('a', np.int64)]),
395 ... np.array([10., 20., 30.])),
396 ... usemask=False, asrecarray=True)
397 rec.array([( 1, 10.), ( 2, 20.), (-1, 30.)],
398 dtype=[('a', '<i8'), ('f1', '<f8')])
399
400 Notes
401 -----
402 * Without a mask, the missing value will be filled with something,
403 depending on what its corresponding type:
404
405 * ``-1`` for integers
406 * ``-1.0`` for floating point numbers
407 * ``'-'`` for characters
408 * ``'-1'`` for strings
409 * ``True`` for boolean values
410 * XXX: I just obtained these values empirically
411 """
412 # Only one item in the input sequence ?
413 if (len(seqarrays) == 1):
414 seqarrays = np.asanyarray(seqarrays[0])
415 # Do we have a single ndarray as input ?
416 if isinstance(seqarrays, (np.ndarray, np.void)):
417 seqdtype = seqarrays.dtype
418 # Make sure we have named fields
419 if seqdtype.names is None:
420 seqdtype = np.dtype([('', seqdtype)])
421 if not flatten or _zip_dtype((seqarrays,), flatten=True) == seqdtype:

Callers 10

test_soloMethod · 0.90
test_solo_w_flattenMethod · 0.90
test_standardMethod · 0.90
test_flattenMethod · 0.90
test_wmasked_arraysMethod · 0.90
test_w_singlefieldMethod · 0.90
test_w_shorter_flexMethod · 0.90
test_singlerecordMethod · 0.90
append_fieldsFunction · 0.85

Calls 8

_zip_dtypeFunction · 0.85
_izip_recordsFunction · 0.85
itemMethod · 0.80
maxFunction · 0.50
dtypeMethod · 0.45
ravelMethod · 0.45
viewMethod · 0.45
__array__Method · 0.45

Tested by 9

test_soloMethod · 0.72
test_solo_w_flattenMethod · 0.72
test_standardMethod · 0.72
test_flattenMethod · 0.72
test_wmasked_arraysMethod · 0.72
test_w_singlefieldMethod · 0.72
test_w_shorter_flexMethod · 0.72
test_singlerecordMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…