+ 2

Why the output of this code is like this?

import numpy arr = numpy.arange(3,15,3) print(arr[2]) Answer is 9 however I am not sure why? Another thing my interpreter is PyCharm is calling out - No module named numpy?

6th Jan 2020, 6:03 PM
THEGreatGatsby
THEGreatGatsby - avatar
2 odpowiedzi
+ 7
1. numpy.arange will make a new array with numbers from 3 to 15 with 3 steps(like using for loop to append the loop number to the array but taken 3 by 3) ex. arr=numpy.arange(3,15,3) => [3,6,9,12] """ similar to: for i in range(3,15,3) arr.append(i) """ print(arr[0]) output: 3 print(arr[2]) output: 9 more info: https://www.geeksforgeeks.org/numpy-arange-JUMP_LINK__&&__python__&&__JUMP_LINK/ edit: thanks to Russ, forgot it doesn't count the last element(15 in this case). 2. I don't understand well the second question, but if it shows you no module named numpy(and if that's the problem), it's because you need to install the library. windows: open cmd -> (write) pip install numpy edit: I haven't worked with PyCharm before so I only know to tell you the windows install option one...
6th Jan 2020, 6:22 PM
molang
molang - avatar
+ 6
numpy.arange(3, 15, 3) will produce the following list : [3, 6, 9, 12] Thus, arr[2] is 9. This function behave like the range function : start, end, step. If your python interpreter is saying 'module X not found', you have to install it using pip. Or it must be possible directly in Pycharm, I don't really know. Look on forums, you'll find an answer.
6th Jan 2020, 6:24 PM
Théophile
Théophile - avatar