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

Function merge_arrays

numpy/lib/recfunctions.py:362–494  ·  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

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

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 9

_zip_dtypeFunction · 0.85
_check_fill_valueFunction · 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