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

Method __repr__

numpy/core/records.py:525–556  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

523 return obj
524
525 def __repr__(self):
526
527 repr_dtype = self.dtype
528 if self.dtype.type is record or not issubclass(self.dtype.type, nt.void):
529 # If this is a full record array (has numpy.record dtype),
530 # or if it has a scalar (non-void) dtype with no records,
531 # represent it using the rec.array function. Since rec.array
532 # converts dtype to a numpy.record for us, convert back
533 # to non-record before printing
534 if repr_dtype.type is record:
535 repr_dtype = sb.dtype((nt.void, repr_dtype))
536 prefix = "rec.array("
537 fmt = 'rec.array(%s,%sdtype=%s)'
538 else:
539 # otherwise represent it using np.array plus a view
540 # This should only happen if the user is playing
541 # strange games with dtypes.
542 prefix = "array("
543 fmt = 'array(%s,%sdtype=%s).view(numpy.recarray)'
544
545 # get data/shape string. logic taken from numeric.array_repr
546 if self.size > 0 or self.shape == (0,):
547 lst = sb.array2string(
548 self, separator=', ', prefix=prefix, suffix=',')
549 else:
550 # show zero-length shape unless it is (0,)
551 lst = "[], shape=%s" % (repr(self.shape),)
552
553 lf = '\n'+' '*len(prefix)
554 if _get_legacy_print_mode() <= 113:
555 lf = ' ' + lf # trailing space
556 return fmt % (lst, lf, repr_dtype)
557
558 def field(self, attr, val=None):
559 if isinstance(attr, int):

Callers

nothing calls this directly

Calls 2

_get_legacy_print_modeFunction · 0.85
dtypeMethod · 0.45

Tested by

no test coverage detected