[cctbxbb] repr for flex arrays

[email protected] Graeme.Winter at diamond.ac.uk
Fri Sep 14 07:29:32 PDT 2018


Hi Folks,

Is there a reason for not having a helpful __repr__ for flex arrays i.e.

Grey-Area:002-decide-when graeme$ dials.python
Python 2.7.14 (default, Apr 17 2018, 15:02:10)
[GCC 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.39.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from dials.array_family import flex
>>> a = flex.double([1, 2, 3])
>>> print a
<scitbx_array_family_flex_ext.double object at 0x1095673c0>

(I have a feeling I asked this before but cannot find reference)

For example

>>> print a.as_numpy_array()
[ 1.  2.  3.]

is more useful… but annoying to type

I appreciate a could be “big” but numpy seems to handle this OK

even - could __repr__ be punned to as_numpy_array(),__repr__()?

Currently it prints the type of the array and its location in ram, which are adequately served by

>>> type(a)
<class 'scitbx_array_family_flex_ext.double'>
>>> print id(a)
4451627968

If I print an array I more often want to see the content and less often the storage class and location (I humbly assert)

Thoughts? I know this tends to confuse and annoy people who are new to flex arrays (and veterans who are busy debugging stuff…)

Many thanks Graeme


-- 
This e-mail and any attachments may contain confidential, copyright and or privileged material, and are for the use of the intended addressee only. If you are not the intended addressee or an authorised recipient of the addressee please notify us of receipt by returning the e-mail and do not use, copy, retain, distribute or disclose the information in or attached to the e-mail.
Any opinions expressed within this e-mail are those of the individual and not necessarily of Diamond Light Source Ltd. 
Diamond Light Source Ltd. cannot guarantee that this e-mail or any attachments are free from viruses and we cannot accept liability for any damage which you may sustain as a result of software viruses which may be transmitted in or with the message.
Diamond Light Source Limited (company no. 4375679). Registered in England and Wales with its registered office at Diamond House, Harwell Science and Innovation Campus, Didcot, Oxfordshire, OX11 0DE, United Kingdom



More information about the cctbxbb mailing list