What meaning is '[: , None]'?

Steven D'Aprano steve at pearwood.info
Sat Jan 2 10:39:36 EST 2016


On Sat, 2 Jan 2016 11:44 pm, Robert wrote:

> Hi,
> 
> I read a code snippet, in which object w_A is:
> 
> 
> w_A
> Out[48]: array([ 0.10708809,  0.94933575,  0.8412686 ,  0.03280939, 
> 0.59985308])


w_A looks like a numpy array of five values.

http://docs.scipy.org/doc/numpy/reference/arrays.html


> Then, I don't know what is '[:  ' below:
> vs_A = w_A[:, None] * xs

The syntax w_A[ ... ] is a "slice" of array w_A. Slicing means to create a
new array from part of the original.

None inside a numpy slice behaves as an alias for numpy.newaxis.

http://docs.scipy.org/doc/numpy/reference/arrays.indexing.html

In this case, w_A[:, None] returns a "view" of the original w_A array.




-- 
Steven




More information about the Python-list mailing list