Python Forum
Where does the array printout come from?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Where does the array printout come from?
#1
I like to understand what lines are generating output. Here's some code:

nums={}
for a in range(25):
    randnum = np.random.randint(0,100)
    print(str(a+1)+': '+str(randnum), end='   ')
    nums[randnum] = nums.get(randnum,0) + 1
#print(nums)
plt.hist(nums, bins=50)
In the [Jupyter Notebook] output, I get the print line from the for loop. I also get a histogram down below. In between, though, I get two 25-element one-dimensional arrays. The first has counts (by bin) and the second has cumulative percentage (I think) by bin. What causes these two arrays to be printed?
Reply
#2
Something like this?
Output:
(array([2., 1., 0., 0., 0., 1., 0., 1., 1., 0., 0., 2., 0., 0., 0., 1., 0., 1., 0., 0., 1., 0., 0., 1., 0., 0., 0., 0., 2., 0., 0., 0., 1., 0., 0., 0., 1., 0., 1., 2., 1., 1., 0., 0., 0., 0., 1., 0., 0., 1.]), array([ 0. , 1.96, 3.92, 5.88, 7.84, 9.8 , 11.76, 13.72, 15.68, 17.64, 19.6 , 21.56, 23.52, 25.48, 27.44, 29.4 , 31.36, 33.32, 35.28, 37.24, 39.2 , 41.16, 43.12, 45.08, 47.04, 49. , 50.96, 52.92, 54.88, 56.84, 58.8 , 60.76, 62.72, 64.68, 66.64, 68.6 , 70.56, 72.52, 74.48, 76.44, 78.4 , 80.36, 82.32, 84.28, 86.24, 88.2 , 90.16, 92.12, 94.08, 96.04, 98. ]), <BarContainer object of 50 artists>)
That is the return value of matplotlib.pyplot.hist(). I haven't used it, but I think Jupiter notebook typically echoes return values and you disable this by ending the line with a semicolon.
Mark17 likes this post
Reply
#3
(Aug-02-2021, 05:29 PM)deanhystad Wrote: Something like this?
Output:
(array([2., 1., 0., 0., 0., 1., 0., 1., 1., 0., 0., 2., 0., 0., 0., 1., 0., 1., 0., 0., 1., 0., 0., 1., 0., 0., 0., 0., 2., 0., 0., 0., 1., 0., 0., 0., 1., 0., 1., 2., 1., 1., 0., 0., 0., 0., 1., 0., 0., 1.]), array([ 0. , 1.96, 3.92, 5.88, 7.84, 9.8 , 11.76, 13.72, 15.68, 17.64, 19.6 , 21.56, 23.52, 25.48, 27.44, 29.4 , 31.36, 33.32, 35.28, 37.24, 39.2 , 41.16, 43.12, 45.08, 47.04, 49. , 50.96, 52.92, 54.88, 56.84, 58.8 , 60.76, 62.72, 64.68, 66.64, 68.6 , 70.56, 72.52, 74.48, 76.44, 78.4 , 80.36, 82.32, 84.28, 86.24, 88.2 , 90.16, 92.12, 94.08, 96.04, 98. ]), <BarContainer object of 50 artists>)
That is the return value of matplotlib.pyplot.hist(). I haven't used it, but I think Jupiter notebook typically echoes return values and you disable this by ending the line with a semicolon.

That gets rid of it. Thanks!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python Flask Realtime system printout (console) ffmpeg jttolleson 3 2,859 Apr-18-2022, 06:39 PM
Last Post: jttolleson

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020