Menu
Coddy logo textTech

Range

Lesson 8 of 18 in Coddy's Numpy Fundamentals course.

Another cool feature of numpy is the opportunity to create various kinds of arrays.

 

np.arange(start, end, increment) creates arrays with incrementing values:

np.arange(5)
>>> array([0, 1, 2, 3, 4])
np.arange(3, 7, dtype=float)
>>> array([3., 4., 5., 6.])
np.arange(1, 2, 0.1)
>>> array([1., 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9])

np<strong>.</strong>linspace(start, end, elements) creates arrays with a fixed amount of elements and with equal spaces between them:

np.linspace(0, 10, 6)
>>> array([ 0.,  2.,  4.,  6.,  8., 10.])
challenge icon

Challenge

Easy

Create a numpy array named ary that will hold exactly 100 elements between 1 and 1000 (including) equally spaced, and print the sum of the array.

Try it yourself

import numpy as np

print(sum(ary)) # Don't touch

All lessons in Numpy Fundamentals