Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Reto Brunner Newsgroups: comp.lang.python Subject: Re: Creating a hot vector (numpy) Date: Mon, 18 Apr 2016 04:05:19 +0000 Lines: 59 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de BlD8dMsuR0lnuvx7ftA4JgG6toQ4EzW4/hS8tOqqZHmw== Return-Path: 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: 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: X-Mailman-Original-References: Xref: csiph.com comp.lang.python:107230 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 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 >