0

I'm using jupyter notebook. Consider ar = np.array([[2,3],[5,6]]).

Then evaluating print ar displays

[[2 3]
 [5 6]]

while just evaluating ar displays

array([[2, 3],
       [5, 6]])

My question is: 1) What command lies actually behind this evaluation in the notebook, how could I reproduce it in a normal IDLE python script?

2) What does the second evaluation mean, which is some form of elaborate priting; does is show me the type of the object + its contents? Shouldn't it actually be ndarray instead of array?

user38525
  • 3
  • 3

1 Answers1

0

1) I think it is more complicated than a single command. I think the code that parses which "interactivity mode" (e.g. display all, just the last line [default]) to run is here. Remember that IPython is like it's own REPL shell and there are lots of different interwoven mechanisms like this one. You could trace back through their source code and try to understand all the mechanisms involved if you wanted to, but I don't think it's a one line solution.

2) This is printing the representation of ar, repr(ar), versus the readable string form of ar. See https://stackoverflow.com/a/2626364/7458681 The reason it is array and not ndarray is that it is not the type of the object that is being printed but instead the function required in order to be able to recreate the object such that eval(repr(ar)) == ar.

Louise Davies
  • 14,781
  • 6
  • 38
  • 41