Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #101142 > unrolled thread

What meaning is '[: , None]'?

Started byRobert <rxjwg98@gmail.com>
First post2016-01-02 04:44 -0800
Last post2016-01-02 07:41 -0800
Articles 3 — 3 participants

Back to article view | Back to comp.lang.python


Contents

  What meaning is '[: , None]'? Robert <rxjwg98@gmail.com> - 2016-01-02 04:44 -0800
    Re: What meaning is '[: , None]'? Steven D'Aprano <steve@pearwood.info> - 2016-01-03 02:39 +1100
    Re: What meaning is '[: , None]'? Rustom Mody <rustompmody@gmail.com> - 2016-01-02 07:41 -0800

#101142 — What meaning is '[: , None]'?

FromRobert <rxjwg98@gmail.com>
Date2016-01-02 04:44 -0800
SubjectWhat meaning is '[: , None]'?
Message-ID<5607ba13-100b-411c-824a-de80c3c52e33@googlegroups.com>
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])


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


I don't find the answer after searching around 
Could you explain above code to me?
Thanks,

[toc] | [next] | [standalone]


#101154

FromSteven D'Aprano <steve@pearwood.info>
Date2016-01-03 02:39 +1100
Message-ID<5687ef39$0$1588$c3e8da3$5496439d@news.astraweb.com>
In reply to#101142
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

[toc] | [prev] | [next] | [standalone]


#101155

FromRustom Mody <rustompmody@gmail.com>
Date2016-01-02 07:41 -0800
Message-ID<335bf0cc-b25e-43b6-be0a-94a94ce0eb73@googlegroups.com>
In reply to#101142
On Saturday, January 2, 2016 at 6:14:24 PM UTC+5:30, 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])
> 
> 
> Then, I don't know what is '[:  ' below:
> vs_A = w_A[:, None] * xs
> 
> 
> I don't find the answer after searching around 
> Could you explain above code to me?
> Thanks,

You probably want to search for 'slice/slicing' and 'indexing'
I get this
http://docs.scipy.org/doc/numpy-1.10.0/reference/arrays.indexing.html

[Note: I dont know much about this]

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web