Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'operator': 0.03; 'syntax': 0.03; 'column': 0.07; 'valueerror:': 0.07; 'python': 0.09; '[0,': 0.09; 'be:': 0.09; 'cc:addr:python-list': 0.10; 'index': 0.13; '(resulting': 0.16; '1:]': 0.16; '3],': 0.16; 'cc:name:python list': 0.16; 'columns': 0.16; 'fancy': 0.16; 'guessing': 0.16; 'numpy': 0.16; 'operands': 0.16; 'skips': 0.16; 'url:whatsnew': 0.16; 'wrote:': 0.17; 'element': 0.17; '>>>': 0.18; 'trying': 0.21; 'import': 0.21; '"",': 0.22; '15,': 0.23; 'cc:2**1': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; '(most': 0.27; 'i.e.': 0.27; 'message-id:@mail.gmail.com': 0.27; 'arrays': 0.29; 'array': 0.29; 'included': 0.29; "i'm": 0.29; 'error': 0.30; 'url:python': 0.32; 'file': 0.32; '-----': 0.32; 'could': 0.32; '11,': 0.33; 'traceback': 0.33; 'received:google.com': 0.34; 'received:209.85': 0.35; 'list.': 0.35; 'url:org': 0.36; 'two': 0.37; 'received:209': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'url:docs': 0.38; 'several': 0.39; 'url:5': 0.61; 'broadcast': 0.65; 'sum': 0.66; '2013': 0.84; 'continuous;': 0.84; 'oscar': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:mime-version:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=mxfx2VUBnKIHPSATX5jc2YveUnzKhDwxJQ0wfn1GQ6o=; b=Knb6qzoe+HwEcEpGBuiid5Gke/mOSMXYfyJ86U/U2Lf2q6sDSEgKRblPfAvzSim0l6 8jcg3Kyz50Rcq5UWDaSPo7A85h74YDIG9ZZENdWXbSKIi/pB2MSXJwgOL9KO85ZYGYRq Dh0osWXvN5ru5LgwQ8QXQ2zzxnIFWoN2hOhDUywks4+JbCzEL5vOV4+wQ3DUQm9BBuEI 4sI67dNZizOeCoKNysEZY5EOtwvIq9mjLGEc7RcPBfpLZ0GzyPOKX0fpaHyMQNmmOaT3 D/cl/liaqeBTwhz4J82PIRZdI5r9Fqg0BT2DIS9wzQlcKBeUgZlZci52uW8Wczp7p3E/ LLxA== X-Received: by 10.152.131.137 with SMTP id om9mr784267lab.18.1360232830960; Thu, 07 Feb 2013 02:27:10 -0800 (PST) MIME-Version: 1.0 In-Reply-To: <978854241.861004.1360229867027.JavaMail.root@sequans.com> References: <016601ce047f$d22ee750$768cb5f0$@nmr.mgh.harvard.edu> <978854241.861004.1360229867027.JavaMail.root@sequans.com> From: Oscar Benjamin Date: Thu, 7 Feb 2013 10:26:50 +0000 Subject: Re: Plotting syntax To: Jean-Michel Pichavant Content-Type: text/plain; charset=ISO-8859-1 Cc: Python List , Vladimir Ivkovic X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 63 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1360232832 news.xs4all.nl 6917 [2001:888:2000:d::a6]:33201 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:38343 On 7 February 2013 09:37, Jean-Michel Pichavant wrote: > ----- Original Message ----- > >> Hi Python experts, >> I am working with an array of data and am trying to plot several >> columns of data which are not continuous; i.e. I would like to plot >> columns 1:4 and 6:8, without plotting column 5. The syntax I am >> currently using is: >> >> oplot (t,d[:,0:4]) >> [SNIP] > > x = x[0:4]+ x[5:8] > y = y[0:4]+ y[5:8] > > skips the element at index 4, meaning the fifth columns. > Alternatively, > > x = x[:4]+ x[5:] > y = y[:4]+ y[5:] > > skips the 5th element without regard for the length of the list. > http://docs.python.org/release/2.3.5/whatsnew/section-slices.html I'm guessing from the multi-dimensional slice syntax that d is a numpy array in which case the + operator attempts to sum the two arrays element-wise (resulting in an error if they are not the same shape): >>> from numpy import array >>> a = array([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]]) >>> a array([[ 1, 2, 3], [ 4, 5, 6], [ 7, 8, 9], [10, 11, 12]]) >>> a[:,0] array([ 1, 4, 7, 10]) >>> a[:,1] array([ 2, 5, 8, 11]) >>> a[:,0] + a[:,1] array([ 3, 9, 15, 21]) >>> a[:,0] + a[:, 1:] Traceback (most recent call last): File "", line 1, in ValueError: operands could not be broadcast together with shapes (4) (4,2) To do this with a numpy array use fancy indexing: >>> a[:, [0, 2]] array([[ 1, 3], [ 4, 6], [ 7, 9], [10, 12]]) So a solution could be: included = [0, 1, 2, 3, 5, 6, 7] oplot (t,d[:, included]) Oscar