It is not possible to understand the matplotlib example, where there are both ellipses and colons, probably related to indexes

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])?

+3
source share
2 answers

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[...,3] a[:,:,3], a .

+5

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]])
+3

All Articles