Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #107211
| Path | csiph.com!aioe.org!.POSTED!not-for-mail |
|---|---|
| From | Paulo da Silva <p_s_d_a_s_i_l_v_a_ns@netcabo.pt> |
| Newsgroups | comp.lang.python |
| Subject | Creating a hot vector (numpy) |
| Date | Mon, 18 Apr 2016 01:46:25 +0100 |
| Organization | Aioe.org NNTP Server |
| Lines | 46 |
| Message-ID | <nf1aor$kiu$1@gioia.aioe.org> (permalink) |
| NNTP-Posting-Host | rpgRlhg9tMo1Vs7b/IQ9OA.user.gioia.aioe.org |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8 |
| Content-Transfer-Encoding | 7bit |
| X-Complaints-To | abuse@aioe.org |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 |
| X-Mozilla-News-Host | news://nntp.aioe.org:119 |
| X-Notice | Filtered by postfilter v. 0.8.2 |
| Xref | csiph.com comp.lang.python:107211 |
Show key headers only | View raw
Hi all.
I have seen this "trick" to create a hot vector.
In [45]: x
Out[45]: array([0, 1])
In [46]: y
Out[46]: array([1, 1, 1, 0, 0, 1, 0, 0], dtype=uint8)
In [47]: y[:,None]
Out[47]:
array([[1],
[1],
[1],
[0],
[0],
[1],
[0],
[0]], dtype=uint8)
In [48]: x==y[:,None]
Out[48]:
array([[False, True],
[False, True],
[False, True],
[ True, False],
[ True, False],
[False, True],
[ True, False],
[ True, False]], dtype=bool)
In [49]: (x==y[:,None]).astype(np.float32)
Out[49]:
array([[ 0., 1.],
[ 0., 1.],
[ 0., 1.],
[ 1., 0.],
[ 1., 0.],
[ 0., 1.],
[ 1., 0.],
[ 1., 0.]], dtype=float32)
How does this (step 48) work?
Thanks
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
Creating a hot vector (numpy) Paulo da Silva <p_s_d_a_s_i_l_v_a_ns@netcabo.pt> - 2016-04-18 01:46 +0100
Re: Creating a hot vector (numpy) Reto Brunner <brunnre8@gmail.com> - 2016-04-18 04:05 +0000
Re: Creating a hot vector (numpy) Paulo da Silva <p_s_d_a_s_i_l_v_a_ns@netcabo.pt> - 2016-04-18 16:38 +0100
csiph-web