1

I am new to Numpy and deep learning. I encountered such a snippet when learning about layer normalization.

a=array([[[-0.66676328, -0.95822262,  1.2951657 ,  0.67924618],
        [-0.46616455, -0.39398589,  1.95926177,  2.36355916],
        [-0.39897415,  0.80353481, -1.46488175,  0.55339737]],
 
       [[-0.66223895, -0.16435625, -1.96494932, -1.07376919],
        [ 1.30338369, -0.19603094, -1.43136723, -1.0207508 ],
        [ 0.8452505 , -0.08878595, -0.5211611 ,  0.10511936]]])
u=np.mean(a, axis=(2,))
s = np.std(a, axis=(2,))
 
y = a-u[...,None]
y = y/s[...,None]
print(y)

########################Output###################################
array([[[-0.80954074, -1.12241971,  1.29657224,  0.63538821],
        [-1.0214588 , -0.96610083,  0.83874033,  1.14881929],
        [-0.30472338,  1.04125172, -1.49779981,  0.76127147]],
 
       [[ 0.46047519,  1.21440667, -1.51218696, -0.16269489],
        [ 1.56757537,  0.13400543, -1.04708279, -0.65449801],
        [ 1.53885365, -0.35203004, -1.2273397 ,  0.04051609]]])

What does [..., None] mean in Numpy? Thanks!

Jimmy Zhao
  • 303
  • 2
  • 17
  • 1
    Does this answer your question? [What does the Ellipsis object do?](https://stackoverflow.com/questions/772124/what-does-the-ellipsis-object-do) – azro Jan 08 '21 at 15:13
  • 1
    in short, it adds one more dimension. You can search `numpy broadcast` on SO or google to see as why we need to do so. – Quang Hoang Jan 08 '21 at 15:13

1 Answers1

1

None is an alias for the newaxis object. It creates an axis with length 1, essentially adding one more dimension. This can be useful for matrix multiplication etc.

Edmund
  • 332
  • 1
  • 9