Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extracting every 3rd data in an array

I have thousand of data for x and y, for this case i will just use 12 data. The array are used to plot a graph

x = np.array([1000,2000,3000,4000,5000,6000,7000,8000,9000,10000,11000,12000])
y = np.array([1,2,3,4,5,6,7,8,9,10,11,12])
py.plot(x,y)

How can i extract every [3] multiplication for me to plot? For Example

x = np.array([3000,6000,9000,12000])
y = np.array([3,6,9,12])
py.plot(x,y)

How can i extract every [5] multiplication for me to plot ? For Example

x = np.array([5000,10000])
y = np.array([5,10])
py.plot(x,y)

1 Answers

Extract every third item starting with the third item (one dimensional array)

x[2::3], y[2::3]

Extract every fifth item starting with the fifth item (one dimensional array)

x[4::5], y[4::5]
like image 81
wwii Avatar answered Mar 28 '26 12:03

wwii