Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialspencer tintorri
6,184 PointsAppending [fake_log] at ~11:30
Appending fake_log
fails, because the shapes don't match
study_minutes = np.append(study_minutes, fake_log, axis=0)
The workaround is to append [fake_log]
study_minutes = np.append(study_minutes, [fake_log], axis=0)
I wasn't clear on why this works. The best I can come up with is:
# the previous study_minutes was shape (2, 100)
# np.append returns a new array
# we're seeding this new array with the original study_minutes
# and appending a new, 3rd row of 100 items, which is [fake_log]
# the new returned array is shape (3, 100)
# trying to append fake_log (without brackets) will error
# because study_minutes is 2d and fake_log is 1d
# the workaround is to append [fake_log] (with brackets)
# [fake_log] is a list, whose contents are 1 array: fake_log
# [fake_log] is a 2d object, and matches the 2d shape of
# study_minutes, and can be appended using np.append
Can someone help explain this part a bit better? Thank you.