I have a question about this matplotlib example .
Here is the part I don't understand
def update_line(num, data, line): line.set_data(data[...,:num]) return line,
What does it do line.set_data(data[...,:num])?
line.set_data(data[...,:num])
This is a special syntax provided by numpy for slicing in multidimensional arrays. The general syntax a[s1,s2, ... , sn], where siis the expression used for regular slicing or indexing sequences, and defines the desired slice in the ith dimension. Eg a[5,2:3,1::2].
a[s1,s2, ... , sn]
si
a[5,2:3,1::2]
... - . , a[...,3] a[:,:,3], a .
...
a[...,3]
a[:,:,3]
a
numpy. numpy ... () :.
numpy
:
docs:
: , , x.ndim. , :.
In : x = numpy.array(range(8)).reshape(2,2,2) In : x Out: array([[[0, 1], [2, 3]], [[4, 5], [6, 7]]]) In : x[...,0] Out: array([[0, 2], [4, 6]]) In : x[:,:,0] Out: array([[0, 2], [4, 6]])