Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Strange... What does [::5,0] mean

I found a webpage which explaining how to use set_xticks and . set_xticklabels.

And they set set_xticks and 'set_xticklabels' as following...

ax.set_xticks(xx[::5,0])
ax.set_xticklabels(times[::5])
ax.set_yticks(yy[0,::5])
ax.set_yticklabels(dates[::5])

What does [::5,0] exactly mean..

I don't have any idea.....

like image 987
Suzuki Soma Avatar asked Dec 20 '22 02:12

Suzuki Soma


1 Answers

For a numpy array, the notation[::5,6] means to take the 6th column for that array and then in the 6th column, every 5th row starting at the first row till the last row.

Example -

In [12]: n = np.arange(100000)
In [17]: n.shape = (500,200)

In [18]: n[::1,2]
Out[18]:
array([    2,   202,   402,   602,   802,  1002,  1202,  1402,  1602,
        1802,  2002,  2202,  2402,  2602,  2802,  3002,  3202,  3402,
        3602,  3802,  4002,  4202,  4402,  4602,  4802,  .....])

In [19]: n[::5,2]
Out[19]:
array([    2,  1002,  2002,  3002,  4002,  5002,  6002,  ...])

Reference on numpy array slicing here , if you are interested.

like image 104
Anand S Kumar Avatar answered Dec 26 '22 10:12

Anand S Kumar