Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

numpy generate sequence from 0 to n

import numpy as np
n = 10
v1 = np.arange(n) # from 0 (included) to n (excluded) with step 1
v1
>>> array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
start = 5
v2 = np.arange(start, n) # from start to n with step 1
v2
>>> array([5, 6, 7, 8, 9])
s = 2
v3 = np.arange(n, s) # from 0 to n with step 2
>>> array([0, 2, 4, 6, 8])
 
PREVIOUS NEXT
Tagged: #numpy #generate #sequence
ADD COMMENT
Topic
Name
6+3 =