Oct-17-2018, 02:58 AM
Hi All,
I'm a Python newbie, so this is probably a very simple (perhaps stupid) question that I'm asking...but for the life of me, I cannot understand how the code below works...to give the output it does:
Okay, just to clarify though...that code pertains to NumPy...so not really a straight Python question per se.
[[2, 3, 4],
[4, 5, 6],
[6, 7, 8]]
If someone could please help me understand what is going on (within the "np.array()" portion), which produces the numbers in the 3D array, that would be super helpful
I specifically cannot understand what the first part does i.e. "range(i, i + 3)"...and how it has any bearing on/relation to the second part i.e. "for i in [2, 4, 6]"
I might as well throw in another question: Can something like this (3D array) be achieved in straight-up Python as well? If yes, how?
Thanks.
I'm a Python newbie, so this is probably a very simple (perhaps stupid) question that I'm asking...but for the life of me, I cannot understand how the code below works...to give the output it does:
Okay, just to clarify though...that code pertains to NumPy...so not really a straight Python question per se.
import numpy as np np.array([range(i, i + 3) for i in [2, 4, 6]])The result from the above is as follows:
[[2, 3, 4],
[4, 5, 6],
[6, 7, 8]]
If someone could please help me understand what is going on (within the "np.array()" portion), which produces the numbers in the 3D array, that would be super helpful

I specifically cannot understand what the first part does i.e. "range(i, i + 3)"...and how it has any bearing on/relation to the second part i.e. "for i in [2, 4, 6]"
I might as well throw in another question: Can something like this (3D array) be achieved in straight-up Python as well? If yes, how?
Thanks.