type(np.newaxis)NoneType
Np.newaxis in use and functionally equivalent to none, in fact, is an alias of none.
1. Np.newaxis's Practical
>> x = np.arange(3)>> xarray([0, 1, 2])>> x.shape(3,)>> x[:, np.newaxis]array([[0], [1], [2]])>> x[:, None]array([[0], [1], [2]])>> x[:, np.newaxis].shape (3, 1)
2. A row vector is returned when a column of a multidimensional array is indexed
>>> X = np.array([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]])>>> X[:, 1]array([2, 6, 10]) % 这里是一个行>>> X[:, 1].shape % X[:, 1] 的用法完全等同于一个行,而不是一个列,(3, )
So, a correct way to index is:
>>>X[:, 1][:, np.newaxis]array([[2], [6], [10]])
If you want to make the concatenation (cascade) of the second and fourth columns:
>>>X_sub = np.hstack([X[:, 1][:, np.newaxis], X[:, 3][:, np.newaxis]]) % hstack:horizontal stack,水平方向上的层叠>>>X_subarray([[2, 4] [6, 8] [10, 12]])
Np.newaxis adds an axis to Numpy.ndarray (multidimensional array)