Is there a way to view arrays like Matlab has in the workspace variables?

I have always found it useful to open up an array (matrix in Matlab) to see the values in a matrix/vector when debugging. For instance, if I see a vector is just a bunch of ones and zeros, I can tell if that is the expected output or not. I am learning on Jupyter notebook, so I imagine its interface dependent. But how else do people do a rapid check of matrix values to tell if they're bogus or not?

Posted Dec 22, 2020, 11:03 AM UTC

13
jarofsalamanders•

Spyder has a variable viewer you can use, but for largerish arrays that I want to really get a good look at I export to excel using pandas. But, for big arrays I have problems with it causing my python to stop working, so if your array is too big slice it into pieces if you can. Fortunately this has always worked for even the largest arrays I've dealt with because its typically simulation data where several simulations are chunked together into one array.

2
ES-Alexander•

Just print them. If it’s a small matrix you can just print the whole thing, and if you’re interested in a particular part of it you can slide it and print that. Assuming you’re using numpy arrays you can slice multiple dimensions easily, so you can do print(data[233:241, 15:18]) to display columns 15-17 at the 234th row up to the 241st (because zero indexing and open upper bound).

Jupyter also just displays the last value of a cell, so you can just have

# normal cell stuff, to do with data
...
data

to display the full array.

2
backtickbot•

Fixed formatting.

Hello, ES-Alexander: code blocks using triple backticks (```) don't work on all versions of Reddit!

Some users see this / this instead.

To fix this, indent every line with 4 spaces instead.

FAQ

^(You can opt out by replying with backtickopt6 to this comment.)

1