[Numpy-discussion] numpy pprint?
Foad Sojoodi Farimani
f.s.farimani at gmail.com
Tue Nov 6 02:26:02 EST 2018
Thanks for the reply. I will write in between your lines:
On Tue, Nov 6, 2018 at 6:11 AM Mark Harfouche <mark.harfouche at gmail.com>
> Visualizing data is definitely a complex field. I definitely feel your
I have actually been using numpy for a couple of years without noticing
these issues. recently I have been trying to encourage my collogues to move
from MATLAB to Python and also prepare some workshops for PhD network of my
> Printing your data is but one way of visualizing it, and probably only
> useful for very small and constrained datasets.
well actually it can be very useful. Consider Pandas .head() and .tail()
methods or Sympy's pretty printing functionalities. for bigger datasets the
function can get the terminals width and height and then based on the input
(U(n),D(n),L(n),R(n),UR(n,m),UL(n,m),DR(n,m),DL(n,m)) display what can be
shown and put horizontal 3-dots \u2026 … or vertical/inclined ones. Or id
it is Jupyter then one can use Markdown/LaTeX for pretty printing or even
HTML to add sliders as suggested by Eric.
> Have you looked into set_printoptions
> to see how numpy’s existing capabilities might help you with your
This is indeed very useful. specially the threshold option can help a lot
with adjusting the width. but only for specific cases.
> The code you showed seems quite good. I wouldn’t worry about performance
> when it comes to functions that will seldom be called in tight loops.
Thanks but I know it is very bad:
- it does not work properly for floats
- it only works for 1D and 2D
- there can be some recursive function I believe.
As you’ll learn more about python and numpy, you’ll keep expanding it to
> include more use cases.
> For many of my projects, I create small submodules for visualization
> tailored to the specific needs of the particular project.
> I’ll try to incorporate your functions and see how I use them.
Thanks a lot. looking forwards to your feedback
> Your original post seems to have some confusion about C Style vs F Style
> ordering. I hope that has been resolved.
I actually came to the conclusion that calling it C-Style or F-Style or
maybe row-major column-major are bad practices. Numpy's ndarrays are not
mathematical multidimensional arrays but Pythons nested, homogenous and
uniform lists. it means for example 1, , [] and [[]] are all
different, while in all other mathematical languages out there (including
Sympy's matrices) they are the same.
> There is also a lot of good documentation
> about transitioning from matlab.
I have seen this one and many others, which I'm trying to comprehend and
then put in some slides made in Jupyter notebooks. Maybe when they are
ready I will create a GitHub repo and upload them alongside the possible
video recordings of the workshops.
> On Mon, Nov 5, 2018 at 4:46 PM Foad Sojoodi Farimani <
> f.s.farimani at gmail.com> wrote:
>> Hello everyone,
>> Following this question <https://stackoverflow.com/q/53126305/4999991>,
>> I'm convinced that numpy ndarrays are not MATLAB/mathematical
>> multidimentional matrices and I should stop expecting them to be. However I
>> still think it would have a lot of benefit to have a function like sympy's
>> pprint to pretty print. something like pandas .head and .tail method plus
>> .left .right .UpLeft .UpRight .DownLeft .DownRight methods. when nothing
>> mentioned it would show 4 corners and put dots in the middle if the array
>> is to big for the terminal.
>> NumPy-Discussion mailing list
>> NumPy-Discussion at python.org
> NumPy-Discussion mailing list
> NumPy-Discussion at python.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the NumPy-Discussion