Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #54423
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| 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.024 |
| X-Spam-Evidence | '*H*': 0.95; '*S*': 0.00; 'skip:[ 20': 0.04; 'argument': 0.05; 'attribute': 0.07; 'cc:addr:python-list': 0.11; '(2,': 0.16; 'accepts': 0.16; 'brackets': 0.16; 'cc:name:python list': 0.16; 'considers': 0.16; 'element,': 0.16; 'function?': 0.16; 'numpy': 0.16; 'tuple.': 0.16; 'wrote:': 0.18; 'shape': 0.19; '>>>': 0.22; 'import': 0.22; 'cc:addr:python.org': 0.22; 'tells': 0.24; 'cc:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'tried': 0.27; 'array': 0.29; 'message-id:@mail.gmail.com': 0.30; '(which': 0.31; 'page.': 0.31; 'tuples': 0.31; 'checked': 0.32; 'checking': 0.33; 'but': 0.35; 'received:google.com': 0.35; 'thanks': 0.36; 'url:org': 0.36; 'should': 0.36; 'skip:- 20': 0.37; 'skip:[ 10': 0.38; 'rather': 0.38; 'according': 0.40; 'dave': 0.60; 'helps': 0.61; 'length': 0.61; 'simply': 0.61; 'first': 0.61; 'skip:n 10': 0.64; 'square': 0.74; 'difference.': 0.84; 'oscar': 0.84; 'url:reference': 0.84; 'angel': 0.91; '2013': 0.98 |
| 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=pamLz2SNHBBg9788nNmH57/rQAJU/nEWyH2VJ6rv5kA=; b=BElbAFA0BubVYVaLn4BovtNDoNJ2eytYzXmKswO8GktLbkSYvpg/VeZwoTeYZX2kWr foardqz9nRCnlloOO1F4yyx0sESWgxMcVV9sE8xlxItkLAFFMABNlp2Fe9zqQuqbbAAP H28mn+ELhQCfTAo+xwgDlJjJiSR+RyhUln6tHXw4UMhv3E5TCRIrj+HRZtz6Ce8XxDS7 FPQ61oV3hzHc8C8Af0rKP+7n8/HkuVtpjmCKpeEirm7swxFH9IVBgcSpF0VvxmtIndCP JZrFcQF6sj8PXDFj6j8YzOck96E6eBNQIJl2Jz5FPWX3BoooVfvpb053/SeEtJRAwlZg 33Kg== |
| X-Received | by 10.52.103.35 with SMTP id ft3mr1270565vdb.5.1379601449752; Thu, 19 Sep 2013 07:37:29 -0700 (PDT) |
| MIME-Version | 1.0 |
| In-Reply-To | <l1d0j5$jd0$1@ger.gmane.org> |
| References | <73ee6fa3-baa6-4178-8596-5f88bbd0bfa2@googlegroups.com> <f1b29ea6-b4db-4636-8042-7c531ed8e99a@googlegroups.com> <l1d0j5$jd0$1@ger.gmane.org> |
| From | Oscar Benjamin <oscar.j.benjamin@gmail.com> |
| Date | Thu, 19 Sep 2013 15:37:09 +0100 |
| Subject | Re: linregress and polyfit |
| To | Dave Angel <davea@davea.name> |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Cc | Python List <python-list@python.org> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| 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> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.149.1379601457.18130.python-list@python.org> (permalink) |
| Lines | 55 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1379601458 news.xs4all.nl 15908 [2001:888:2000:d::a6]:51322 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:54423 |
Show key headers only | View raw
On 18 September 2013 20:57, Dave Angel <davea@davea.name> wrote:
> On 18/9/2013 09:38, chitturk@uah.edu wrote:
>
>> Thanks - that helps ... but it is puzzling because
>>
>> np.random.normal(0.0,1.0,1) returns exactly one
>> and when I checked the length of "z", I get 21 (as before) ...
>>
>>
>
> I don't use Numpy, so this is just a guess, plus reading one web page.
>
> According to:
> http://docs.scipy.org/doc/numpy/reference/generated/numpy.random.normal.html
>
> the 3rd argument to normal should be a tuple. So if you want a single
> element, you should have made it (1,)
Numpy accepts ints in place of shape tuples so this makes no difference.
> As for checking the 'length of "z"' did you just use the len() function?
> That just tells you the first dimension. Have you tried simply printing
> out "z" ?
Exactly. What you need to check is the shape attribute (converting to
numpy array first if necessary):
>>> import numpy as np
>>> a = np.random.normal(0, 1, 1)
>>> a
array([-0.90292348])
>>> a.shape
(1,)
>>> a[0]
-0.90292348393433797
>>> np.array(a[0])
array(-0.902923483934338)
>>> np.array(a[0]).shape
()
>>> [a, a]
[array([-0.90292348]), array([-0.90292348])]
>>> np.array([a, a])
array([[-0.90292348],
[-0.90292348]])
>>> np.array([a, a]).shape
(2, 1)
>>> np.random.normal(0, 1, 2).shape
(2,)
The square brackets in 'array([-0.90292348])' indicate that numpy
considers this to be a 1-dimensional array of length 1 rather than a
scalar value (which would have an empty shape tuple).
Oscar
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
linregress and polyfit Krishnan <chitturk@uah.edu> - 2013-09-17 19:34 -0700
Re: linregress and polyfit Josef Pktd <josef.pktd@gmail.com> - 2013-09-17 21:25 -0700
Re: linregress and polyfit chitturk@uah.edu - 2013-09-18 06:38 -0700
Re: linregress and polyfit Dave Angel <davea@davea.name> - 2013-09-18 19:57 +0000
Re: linregress and polyfit Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-09-19 15:37 +0100
Re: linregress and polyfit chitturk@uah.edu - 2013-09-19 04:32 -0700
csiph-web