MCPcopy Index your code
hub / github.com/numpy/numpy / drop_fields

Function drop_fields

numpy/lib/recfunctions.py:505–563  ·  view source on GitHub ↗

Return a new array with fields in `drop_names` dropped. Nested fields are supported. Parameters ---------- base : array Input array drop_names : string or sequence String or sequence of strings corresponding to the names of the fields to drop. u

(base, drop_names, usemask=True, asrecarray=False)

Source from the content-addressed store, hash-verified

503
504@array_function_dispatch(_drop_fields_dispatcher)
505def drop_fields(base, drop_names, usemask=True, asrecarray=False):
506 """
507 Return a new array with fields in `drop_names` dropped.
508
509 Nested fields are supported.
510
511 Parameters
512 ----------
513 base : array
514 Input array
515 drop_names : string or sequence
516 String or sequence of strings corresponding to the names of the
517 fields to drop.
518 usemask : {False, True}, optional
519 Whether to return a masked array or not.
520 asrecarray : string or sequence, optional
521 Whether to return a recarray or a mrecarray (`asrecarray=True`) or
522 a plain ndarray or masked array with flexible dtype. The default
523 is False.
524
525 Examples
526 --------
527 >>> import numpy as np
528 >>> from numpy.lib import recfunctions as rfn
529 >>> a = np.array([(1, (2, 3.0)), (4, (5, 6.0))],
530 ... dtype=[('a', np.int64), ('b', [('ba', np.double), ('bb', np.int64)])])
531 >>> rfn.drop_fields(a, 'a')
532 array([((2., 3),), ((5., 6),)],
533 dtype=[('b', [('ba', '<f8'), ('bb', '<i8')])])
534 >>> rfn.drop_fields(a, 'ba')
535 array([(1, (3,)), (4, (6,))], dtype=[('a', '<i8'), ('b', [('bb', '<i8')])])
536 >>> rfn.drop_fields(a, ['ba', 'bb'])
537 array([(1,), (4,)], dtype=[('a', '<i8')])
538 """
539 if _is_string_like(drop_names):
540 drop_names = [drop_names]
541 else:
542 drop_names = set(drop_names)
543
544 def _drop_descr(ndtype, drop_names):
545 names = ndtype.names
546 newdtype = []
547 for name in names:
548 current = ndtype[name]
549 if name in drop_names:
550 continue
551 if current.names is not None:
552 descr = _drop_descr(current, drop_names)
553 if descr:
554 newdtype.append((name, descr))
555 else:
556 newdtype.append((name, current))
557 return newdtype
558
559 newdtype = _drop_descr(base.dtype, drop_names)
560
561 output = np.empty(base.shape, dtype=newdtype)
562 output = recursive_fill_fields(base, output)

Callers 2

test_drop_fieldsMethod · 0.90
rec_drop_fieldsFunction · 0.85

Calls 4

_is_string_likeFunction · 0.90
_drop_descrFunction · 0.85
recursive_fill_fieldsFunction · 0.85
_fix_outputFunction · 0.85

Tested by 1

test_drop_fieldsMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…