How much of this functionality is available in the tabulate package?   _JM

______
John Mark Agosta                             LinkedIn:
https://www.linkedin.com/in/john-mark-agosta/
johnmark.ago...@gmail.com    Find me at https://medium.com/@johnmark54


On Tue, Aug 5, 2025 at 6:55 AM Андрей Рыбаков via NumPy-Discussion <
numpy-discussion@python.org> wrote:

> Dear all,
>
> I would like to discuss a «cosmetic» feature for numpy.
>
> I find it useful in my day-to-day work to inspect the values of 1D and 2D
> numpy arrays. Typically I was saving the data in the .txt format and then
> used the next best tool to analyse the numbers.
>
> However, I would prefer to be able to just print an array directly in the
> interactive console (python console for instance) and have the printed
> array formatted in such a way that it can be easily read by human eyes.
>
> Now, the type of formatting is subjective. Nevertheless, I would like to
> propose the one that I have converged to over the years.
>
> The proposed implementation is a standalone function, written in pure
> python (as this «visual» representation will be suitable only for the
> reasonable-sized array, then there is no need to worry about the
> performance), for example,
>
>
>
> def decorate_array(
>
>     object: array_like,
>
>     fmt: str,
>
>     header: list,
>
>     footer: list,
>
>     column_header: list,
>
>     footer column: list,
>
>     …,
>
> )
>
>
>
> If the numpy community agrees that this function fits in the package, then
> I would like to adapt the implementation that I am using now. I would open
> a PR, but I saw that it is recommended to ask for an opinion on this
> mailing list first.
>
>
>
> Below are the examples of how this function would behave (again, the style
> is subjective):
>
>
>
> 1. Plain real-valued array
>
>
> decorate_array(
>
>     object = np.random.random((10,3)),
>
>     fmt = ">.4f",
>
> )
>
>
> ┌────────┬────────┬────────┐
>
> │ 0.0410 │ 0.2844 │ 0.4251 │
>
> ├────────┼────────┼────────┤
>
> │ 0.9270 │ 0.7509 │ 0.9892 │
>
> ├────────┼────────┼────────┤
>
> │ 0.7380 │ 0.1245 │ 0.1855 │
>
> ├────────┼────────┼────────┤
>
> │ 0.4738 │ 0.6671 │ 0.8455 │
>
> ├────────┼────────┼────────┤
>
> │ 0.4442 │ 0.5946 │ 0.5874 │
>
> ├────────┼────────┼────────┤
>
> │ 0.0789 │ 0.5374 │ 0.6505 │
>
> ├────────┼────────┼────────┤
>
> │ 0.8006 │ 0.0970 │ 0.4456 │
>
> ├────────┼────────┼────────┤
>
> │ 0.4884 │ 0.4162 │ 0.8283 │
>
> ├────────┼────────┼────────┤
>
> │ 0.5082 │ 0.5625 │ 0.8812 │
>
> ├────────┼────────┼────────┤
>
> │ 0.2013 │ 0.9937 │ 0.3731 │
>
> └────────┴────────┴────────┘
>
>
>
> 2. Headers and footers
>
>
> decorate_array(
>
>     object = np.random.random((2,3)),
>
>     fmt = ">.5f",
>
>     header = ["l-h-corner", "h1", "h2", "h3"],
>
>     footer = ["l-f-corner", "f1", "f2", "f3"],
>
>     column_header = ["ch1", "ch2", "ch3"],
>
>     footer column = ["cf1", "cf2", "cf3"],
>
> )
>
>
> ┌────────────┬─────────┬─────────┬─────────┬─────┐
>
> │ l-h-corner │      h1 │      h2 │      h3 │     │
>
> ├────────────┼─────────┼─────────┼─────────┼─────┤
>
> │        ch1 │ 0.84675 │ 0.80002 │ 0.79360 │ cf1 │
>
> ├────────────┼─────────┼─────────┼─────────┼─────┤
>
> │        ch2 │ 0.93482 │ 0.28542 │ 0.28057 │ cf2 │
>
> ├────────────┼─────────┼─────────┼─────────┼─────┤
>
> │ l-f-corner │      f1 │      f2 │      f3 │     │
>
> └────────────┴─────────┴─────────┴─────────┴─────┘
>
>
>
> 3. Complex numbers
>
>
> ┌──────────────┬──────────────┬──────────────┐
>
> │ 0.60 - i0.12 │ 0.66 + i0.18 │ 0.31 - i0.22 │
>
> ├──────────────┼──────────────┼──────────────┤
>
> │ 0.52 - i0.33 │ 0.05 - i0.03 │ 0.23 + i0.37 │
>
> └──────────────┴──────────────┴──────────────┘
>
>
> There are more verbose examples written in the docs page of my sandbox
> python package, but I am not sure if posting the link to it here would be
> appropriate. The three examples above should be enough to grasp the idea.
>
>
> Best,
>
> Andrey
>
>
> _______________________________________________
> NumPy-Discussion mailing list -- numpy-discussion@python.org
> To unsubscribe send an email to numpy-discussion-le...@python.org
> https://mail.python.org/mailman3//lists/numpy-discussion.python.org
> Member address: johnmark.ago...@gmail.com
>
_______________________________________________
NumPy-Discussion mailing list -- numpy-discussion@python.org
To unsubscribe send an email to numpy-discussion-le...@python.org
https://mail.python.org/mailman3//lists/numpy-discussion.python.org
Member address: arch...@mail-archive.com

Reply via email to