Provide information about ndarray obj. Parameters ---------- obj : ndarray Must be ndarray, not checked. output Where printed output goes. Notes ----- Copied over from the numarray module prior to its removal. Adapted somewhat as only numpy is an opt
(obj, output=None)
| 472 | |
| 473 | |
| 474 | def _info(obj, output=None): |
| 475 | """Provide information about ndarray obj. |
| 476 | |
| 477 | Parameters |
| 478 | ---------- |
| 479 | obj : ndarray |
| 480 | Must be ndarray, not checked. |
| 481 | output |
| 482 | Where printed output goes. |
| 483 | |
| 484 | Notes |
| 485 | ----- |
| 486 | Copied over from the numarray module prior to its removal. |
| 487 | Adapted somewhat as only numpy is an option now. |
| 488 | |
| 489 | Called by info. |
| 490 | |
| 491 | """ |
| 492 | extra = "" |
| 493 | tic = "" |
| 494 | bp = lambda x: x |
| 495 | cls = getattr(obj, '__class__', type(obj)) |
| 496 | nm = getattr(cls, '__name__', cls) |
| 497 | strides = obj.strides |
| 498 | endian = obj.dtype.byteorder |
| 499 | |
| 500 | if output is None: |
| 501 | output = sys.stdout |
| 502 | |
| 503 | print("class: ", nm, file=output) |
| 504 | print("shape: ", obj.shape, file=output) |
| 505 | print("strides: ", strides, file=output) |
| 506 | print("itemsize: ", obj.itemsize, file=output) |
| 507 | print("aligned: ", bp(obj.flags.aligned), file=output) |
| 508 | print("contiguous: ", bp(obj.flags.contiguous), file=output) |
| 509 | print("fortran: ", obj.flags.fortran, file=output) |
| 510 | print( |
| 511 | "data pointer: %s%s" % (hex(obj.ctypes._as_parameter_.value), extra), |
| 512 | file=output |
| 513 | ) |
| 514 | print("byteorder: ", end=' ', file=output) |
| 515 | if endian in ['|', '=']: |
| 516 | print("%s%s%s" % (tic, sys.byteorder, tic), file=output) |
| 517 | byteswap = False |
| 518 | elif endian == '>': |
| 519 | print("%sbig%s" % (tic, tic), file=output) |
| 520 | byteswap = sys.byteorder != "big" |
| 521 | else: |
| 522 | print("%slittle%s" % (tic, tic), file=output) |
| 523 | byteswap = sys.byteorder != "little" |
| 524 | print("byteswap: ", bp(byteswap), file=output) |
| 525 | print("type: %s" % obj.dtype, file=output) |
| 526 | |
| 527 | |
| 528 | @set_module('numpy') |