Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Joel Goldstick Newsgroups: comp.lang.python Subject: Re: Why is there difference between cmd line and .py file? Date: Tue, 5 Jan 2016 15:58:18 -0500 Lines: 73 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de ezPYrsNQT4j4nkaNTZBLJw5e+tFuEqeP9/fQ6D1YwIXw== 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; 'received:209.85.223': 0.03; 'value,': 0.03; '"the': 0.07; 'skip:/ 10': 0.07; 'subject:file': 0.07; 'cc:addr:python-list': 0.09; 'edward': 0.09; 'empty,': 0.09; 'integer,': 0.09; 'list).': 0.09; 'subject:Why': 0.09; 'typed': 0.09; 'jan': 0.11; 'causing': 0.13; 'index': 0.13; 'missed': 0.15; 'file,': 0.15; '2016': 0.16; 'experiments': 0.16; 'index.': 0.16; 'indexerror:': 0.16; 'last)': 0.16; 'numpy': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:between': 0.16; 'variable.': 0.16; 'wrote:': 0.16; '>': 0.18; '(in': 0.18; 'email addr:gmail.com>': 0.18; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'posted': 0.21; 'subject: .': 0.22; 'code.': 0.23; '(or': 0.23; 'thanks,': 0.24; 'import': 0.24; '(most': 0.24; 'header:In-Reply-To:1': 0.24; "i've": 0.25; "doesn't": 0.26; 'define': 0.27; 'right.': 0.27; 'wonder': 0.27; 'message-id:@mail.gmail.com': 0.27; 'function': 0.28; 'print': 0.30; 'url:mailman': 0.30; 'code': 0.30; 'skip:& 30': 0.30; 'error.': 0.31; '"the': 0.32; 'url:python': 0.33; 'traceback': 0.33; 'url:listinfo': 0.34; 'tue,': 0.34; 'list': 0.34; 'received:google.com': 0.35; 'robert': 0.35; 'skip:& 60': 0.35; 'something': 0.35; 'but': 0.36; 'list,': 0.36; 'should': 0.36; 'url:org': 0.36; 'received:209.85': 0.36; 'subject:?': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'skip:& 10': 0.37; 'january': 0.38; 'received:209': 0.38; 'represent': 0.38; 'does': 0.39; "didn't": 0.39; 'url:mail': 0.40; 'your': 0.60; 'john': 0.61; 'show': 0.62; 'real': 0.62; 'linked': 0.63; 'subject:there': 0.66; 'reply': 0.68; 'email addr:panix.com': 0.84; 'to:none': 0.91; 'bears': 0.91; 'joel': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=SLapNKffXHrBSxDbWGBWVgc2XCTeZkdUmYqcs4BizUI=; b=CQx1QXntJJnFxttadwsoLtOv+Jpmquh7lL1Kp4YsthgTS1yrw2SnmK4Jy98UWBTNF+ qJ5lxs6iCFoF/twkFdqQOrtkSBzvlVcW0CMhChx/ZjNQb6poVoPQniaDB5jCuMaa8XMM 0WOxydh4u0BIcxSb69WpSG8pRpbu60sfpy1GraJ3B1sBHut9rMrXikJwOisUlS7XOVKq YDhdBPrE95CKrNlXUrZBBi2JfSboccGwsK8IwxbJevk2qJTe8AMLG7pKEaqbqRyoisZT NV5XA2T9pXWZkvRPznvNjqQb7HlRZ4dFNRUo6wPQBO6d4DRWSWQlk6wK70DQG0+6ygzU Mpog== X-Received: by 10.107.166.6 with SMTP id p6mr58726199ioe.125.1452027498568; Tue, 05 Jan 2016 12:58:18 -0800 (PST) In-Reply-To: X-Content-Filtered-By: Mailman/MimeDel 2.1.20+ X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:101279 On Tue, Jan 5, 2016 at 3:45 PM, Robert wrote: > On Tuesday, January 5, 2016 at 3:37:53 PM UTC-5, John Gordon wrote: > > In Robert < > r--@gmail.com> writes: > > > > > //////////// > > > # represent the experiments > > > head_counts = np.array([5,9,8,4,7]) > > > > The code doesn't define 'np', so this line should produce an error. > > > > The code you linked contains this import: > > > > import numpy as np > > > > However you didn't show it here, so I wonder if you posted the real code. > > > > > sum(expectation_A)[0] > > > > --------------------------------------------------------------------------- > > > IndexError Traceback (most recent call > last) > > > in () > > > ----> 1 sum(expectation_A)[0] > > > > > IndexError: invalid index to scalar variable. > > > ////////////// > > > > The built-in function sum() returns a single value, not a list, so this > > is a reasonable error. > > > > I suspect the code actually intended to call numpy.sum(), which does > > return a list (or something like a list). > > > > -- > > John Gordon A is for Amy, who fell down the stairs > > gordon@panix.com B is for Basil, assaulted by bears > > -- Edward Gorey, "The Gashlycrumb Tinies" > > Thanks, John. When I typed my new thought, your reply came. You are right. > The attached message missed numpy import (In my file, it had). > > Now, I cannot use np.sum. It has an error, see below please. How can I use > the numpy sum()? > > Thanks, > ///////// > import numpy as np > > In [154]: np.sum(expectation_A)[0] > --------------------------------------------------------------------------- > IndexError Traceback (most recent call last) > in () > ----> 1 np.sum(expectation_A)[0] > > IndexError: invalid index to scalar variable. > I've not used numpy, but you should print expectation_A to see what's in it. It may be empty, causing the index. It may be that expectation_A is an integer, not a list > > -- > https://mail.python.org/mailman/listinfo/python-list > -- Joel Goldstick http://joelgoldstick.com/stats/birthdays