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


Groups > comp.lang.python > #107230

Re: Creating a hot vector (numpy)

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Reto Brunner <brunnre8@gmail.com>
Newsgroups comp.lang.python
Subject Re: Creating a hot vector (numpy)
Date Mon, 18 Apr 2016 04:05:19 +0000
Lines 59
Message-ID <mailman.134.1460952337.6324.python-list@python.org> (permalink)
References <nf1aor$kiu$1@gioia.aioe.org> <CAG8ousQ5y63aCUtZmdA+KuywoDqmazKGB-6fay07k7wHyLxoxA@mail.gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
X-Trace news.uni-berlin.de BlD8dMsuR0lnuvx7ftA4JgG6toQ4EzW4/hS8tOqqZHmw==
Return-Path <brunnre8@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.145
X-Spam-Level *
X-Spam-Evidence '*H*': 0.72; '*S*': 0.01; 'true,': 0.04; '0],': 0.16; 'paulo': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'wrote:': 0.16; 'header:In-Reply-To:1': 0.24; 'all.': 0.24; 'mon,': 0.24; 'message-id:@mail.gmail.com': 0.27; 'url:mailman': 0.30; 'url:python': 0.33; 'url:listinfo': 0.34; 'received:google.com': 0.35; 'skip:( 30': 0.35; 'url:org': 0.36; 'received:209.85': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'skip:& 10': 0.37; 'thanks': 0.37; 'received:209': 0.38; 'hi,': 0.38; 'does': 0.39; 'url:mail': 0.40; 'to:addr:python.org': 0.40; 'called': 0.40; 'greetings,': 0.61; 'url:user': 0.63; 'here:': 0.63; 'url:10': 0.79; 'url:scipy': 0.84; 'broadcasting': 0.93; 'hot': 0.97
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=xcI5yBUUPpzDxWzvc16Q9JkhaRGxbY+OKKGqHbC4gd8=; b=SK2C9Z6TMzKqwL9ENAvuZTicWlyBIC5Ni6ZcEByStD8Y3JkJpasek1yVG2PEIQ5R7S J4XhL8t1FxXZrrePP0nqxhMGXdWEFaITfGlgEVN85gtfOYrstDdZMSpRAx8zkXPFPguV uV9CYHvaBXVRWp0t5cubdcxRjYDGYigYgD53g07tmoLa03W5hN0MJDke8ID0+D8rMBHc ZQKZdyXMbuog5JzNXLIW3s4sfGBdBqaIHX6sG3C/wke8HF+OjllpTxo9FxtmAAdSjmbe HgcaQdetX6xuwFhu2LE6kdhmTbHwHqT6I0Z7imE0Hi/MKldekgpVS0NohdU1YYi76ImD 1LfA==
X-Google-DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=xcI5yBUUPpzDxWzvc16Q9JkhaRGxbY+OKKGqHbC4gd8=; b=W8jrgtyGh5NNHcFCP4VpU9nLNgfguQJs4mwGgBRAI/W2STRQZpe7mHIR1HttVfaVLw j1AsbdSS1FwXEH6nRbav/V+3RNTzMJlnGNzZOl4wvPxVbS+gGPXq0YxTMWuOKMlU9pDE kHzV0Fp2a2TK1pcD2mpthHksQZvnVUxZNkknxhCrDip8RZVMVCLJxfgQJtkHWqlp3WQh wmktuG6ADgqom1f4GSIMxvHrHTNPW0iJG9Uf7PKkgDlMZnO2+qqyNmse/EzNu750OC2I h+V7d24FDSZ34Cos1lGXC3CPs9GIgkJwoJfkeJOHPKYokmhLSffcMn8NGClVvMnBlzsG dkwg==
X-Gm-Message-State AOPr4FXDAW+AbdrG2zSYw4GfnqVyi7JIXp9gPqZBW8SQVN3XKeFctiBOrxmXfYf1SKw5AUC/Xc6nRiTicZLLkg==
X-Received by 10.25.89.199 with SMTP id n190mr14197540lfb.16.1460952329571; Sun, 17 Apr 2016 21:05:29 -0700 (PDT)
In-Reply-To <nf1aor$kiu$1@gioia.aioe.org>
X-Content-Filtered-By Mailman/MimeDel 2.1.21
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.21
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID <CAG8ousQ5y63aCUtZmdA+KuywoDqmazKGB-6fay07k7wHyLxoxA@mail.gmail.com>
X-Mailman-Original-References <nf1aor$kiu$1@gioia.aioe.org>
Xref csiph.com comp.lang.python:107230

Show key headers only | View raw


Hi,
It is called broadcasting an array, have a look here:
http://docs.scipy.org/doc/numpy-1.10.1/user/basics.broadcasting.html

Greetings,
Reto

On Mon, Apr 18, 2016, 02:54 Paulo da Silva <p_s_d_a_s_i_l_v_a_ns@netcabo.pt>
wrote:

> 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
> --
> https://mail.python.org/mailman/listinfo/python-list
>

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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