I want to know more numpy to process array. I find that it is different between a[:,None] and a[:,]. I want to dig into where and when to use them.
I try to slove the problem that subtract 1d from 2d array in special way just like numpy-subtract-add-1d-array-from-2d-array where I realise it's different between a[:,None] and a[:,].
>>> import numpy as np
>>> a = np.array([[1,2,3],[4,5,6],[7,8,9]])
>>> a
array([[1, 2, 3],
[4, 5, 6],
[7, 8, 9]])
>>> b = np.array([1,2,3])
>>> b
array([1, 2, 3])
>>> b[:,None]
array([[1],
[2],
[3]])
>>> b[:,]
array([1, 2, 3])
>>> b[None,:]
array([[1, 2, 3]])
>>> a-b[None,:]
array([[0, 0, 0],
[3, 3, 3],
[6, 6, 6]])
>>> b[,:] #false operation!!!
SyntaxError: invalid syntax
>>> a-b
array([[0, 0, 0],
[3, 3, 3],
[6, 6, 6]])
>>> a-b[:,np.newaxis]
array([[0, 1, 2],
[2, 3, 4],
[4, 5, 6]])
Can anyone give me official or specific reference about it? I will really appreciate you!