1

I have the code:

g, g_err = data[:, 4:6].T

I don't know the meaning of [:, 4:6]

especially the first :

and does .T mean transpose?

Darkhogg
  • 13,707
  • 4
  • 22
  • 24
CapKoko
  • 49
  • 1
  • 5

1 Answers1

1

You have a 2D matrix called data, your code takes all elements from the first dimension, marked as :, then takes only elements 4 and 5 in the second dimension, something like this:

>>> np.ones( (7,7 ))
array([[ 1.,  1.,  1.,  1.,  1.,  1.,  1.],
       [ 1.,  1.,  1.,  1.,  1.,  1.,  1.],
       [ 1.,  1.,  1.,  1.,  1.,  1.,  1.],
       [ 1.,  1.,  1.,  1.,  1.,  1.,  1.],
       [ 1.,  1.,  1.,  1.,  1.,  1.,  1.],
       [ 1.,  1.,  1.,  1.,  1.,  1.,  1.],
       [ 1.,  1.,  1.,  1.,  1.,  1.,  1.]])
>>> np.ones( (7,7 ))[:,4:6]
array([[ 1.,  1.],
       [ 1.,  1.],
       [ 1.,  1.],
       [ 1.,  1.],
       [ 1.,  1.],
       [ 1.,  1.],
       [ 1.,  1.]])
>>> 

And yeah, .T means transpose.

Jean-François Fabre
  • 137,073
  • 23
  • 153
  • 219
lenik
  • 23,228
  • 4
  • 34
  • 43