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,105
  • 4
  • 21
  • 24
CapKoko
  • 39
  • 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
  • 131,796
  • 23
  • 122
  • 195
lenik
  • 22,629
  • 4
  • 31
  • 41