Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #98742
| Path | csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Oscar Benjamin <oscar.j.benjamin@gmail.com> |
| Newsgroups | comp.lang.python |
| Subject | Re: Matplotlib error: Value Error: x and y must have same first dimension |
| Date | Fri, 13 Nov 2015 14:04:01 +0000 |
| Lines | 28 |
| Message-ID | <mailman.289.1447423463.16136.python-list@python.org> (permalink) |
| References | <40964e99-cd31-4daa-8f5f-069b09816b3d@googlegroups.com> <201511130834.tAD8YNra005833@fido.openend.se> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| X-Trace | news.uni-berlin.de yxUO6Hl3Em7Hu6aXRsGp+QbfVBBSNJfl17eFnvkhVgpQ== |
| Return-Path | <oscar.j.benjamin@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.001 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'error:': 0.05; 'incompatible': 0.07; 'subject:Error': 0.07; 'valueerror:': 0.07; 'cc:addr:python-list': 0.09; 'creighton': 0.09; 'subject:same': 0.09; 'way:': 0.09; 'python': 0.10; 'subject:error': 0.11; 'thu,': 0.15; 'abhishek': 0.16; 'arrays.': 0.16; 'cc:name:python list': 0.16; 'code?': 0.16; 'dimension': 0.16; 'numpy': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'wrote:': 0.16; 'laura': 0.18; '2015': 0.20; 'cc:addr:python.org': 0.20; 'cc:2**1': 0.22; 'do.': 0.22; '(by': 0.22; 'arguments': 0.22; 'arrays': 0.22; 'converted': 0.22; 'trying': 0.22; 'skip:l 40': 0.23; '(most': 0.24; 'cc:addr:gmail.com': 0.24; 'header:In-Reply- To:1': 0.24; 'command': 0.26; 'error': 0.27; 'message- id:@mail.gmail.com': 0.27; 'converting': 0.27; 'matplotlib': 0.29; 'array': 0.29; 'convert': 0.29; "i'm": 0.30; 'too.': 0.30; 'code': 0.30; 'guess': 0.31; 'getting': 0.33; 'run': 0.33; 'traceback': 0.33; 'file': 0.34; 'lists': 0.34; 'list': 0.34; 'received:google.com': 0.35; 'trouble': 0.35; 'nov': 0.35; 'skip:p 30': 0.35; 'too': 0.36; 'received:209.85': 0.36; 'subject:: ': 0.37; 'skip:s 50': 0.37; 'list.': 0.37; 'received:209': 0.38; 'sure': 0.39; 'some': 0.40; 'your': 0.60; 'cast': 0.66; 'here': 0.66; 'spend': 0.67; 'subject:have': 0.80; '128,': 0.84; 'oscar': 0.84; 'subject:Value': 0.91 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=3HCL7+La31uzHqDhdPoUCBsF/XR18jblKhjduSkDjI0=; b=bjuz5OVX3qk6z4sHkB/aRnfcRaajOl/wraCgTBo66TLmoW4NcxMUSf4+uoMdlBJgJD mYf8YoxxAzR5vCgmkE1LYpaa045n/qaL/ILx7NFqes6pwk3G8/VbLMomptA7EE+8nGNY arpap8gNfiI1+T6Pl0PPSK/iKHxBg9cPB4JidJNnIxx5Ij4Eyx0VO0sujf6qe/nnqww7 JChGunYdZwlt6sgg/w5+IIa6tehgz3Anl6qk6f0HhtcRRw0hqYGLyE5m9k58N1dTS4l4 RZxD8ZjYa9P7uqiyfhIfDz6W3Z5nXqQ8mrTD2X1O5TQgAJyH8+WtREAiTIu0baLWTR6u IYMQ== |
| X-Received | by 10.112.205.194 with SMTP id li2mr10121353lbc.75.1447423461077; Fri, 13 Nov 2015 06:04:21 -0800 (PST) |
| In-Reply-To | <201511130834.tAD8YNra005833@fido.openend.se> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.20+ |
| 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> |
| Xref | csiph.com comp.lang.python:98742 |
Show key headers only | View raw
On 13 November 2015 at 08:34, Laura Creighton <lac@openend.se> wrote:
> In a message of Thu, 12 Nov 2015 17:54:28 -0800, Abhishek writes:
>>I am trying to run some Python code for the last few hours. How can I achieve the effect of "dot divide" from Matlab, in the following code? I am having trouble working with list comprehension and numpy arrays and getting the following error:
>>
>> Traceback (most recent call last):
>> File "Thurs.py", line 128, in <module>
>> plt.plot(np.array(range(1,N/2+2)), Splot[alpha][iii,val]/utot[iii,val],color=cmap(iii/50))
>>
>> ValueError: x and y must have same first dimension
>
> Splot is a list. matplotlib wants 2 numpy arrays. You have to cast
> it with np.array() too.
Actually the plot command is perfectly happy converting lists or lists
of lists etc. to arrays (by calling np.array internally) so you don't
need to convert any of your inputs. By the way: np.arange(1, N/2+2)
would be the usual way to create a numpy array that is a range.
The error here comes because (after both arguments are converted to
arrays) they have incompatible sizes. In other words:
len(range(1,N/2+2)) != len(Splot[alpha][iii,val]/utot[iii,val])
I'm not sure what the solution is as the code is too complex for me to
spend time trying to guess what it's trying to do.
--
Oscar
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Matplotlib error: Value Error: x and y must have same first dimension Abhishek <abhishek.mallela@gmail.com> - 2015-11-12 17:54 -0800 Re: Matplotlib error: Value Error: x and y must have same first dimension Laura Creighton <lac@openend.se> - 2015-11-13 09:34 +0100 Re: Matplotlib error: Value Error: x and y must have same first dimension Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2015-11-13 14:04 +0000 Re: Matplotlib error: Value Error: x and y must have same first dimension Laura Creighton <lac@openend.se> - 2015-11-13 16:43 +0100 Re: Matplotlib error: Value Error: x and y must have same first dimension Abhishek Mallela <abhishek.mallela@gmail.com> - 2015-11-13 11:44 -0600
csiph-web