Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #71513

Re: How can this assert() ever trigger?

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.012
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'transform': 0.07; 'calculating': 0.09; 'happen?': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:How': 0.10; 'python': 0.11; 'def': 0.12; '2],': 0.16; 'arithmetic.': 0.16; 'compares': 0.16; 'docs.': 0.16; 'libraries.': 0.16; 'logiciel': 0.16; 'multiplied': 0.16; 'numpy': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:ever': 0.16; 'zero.': 0.16; '\xe9crit': 0.16; 'modification': 0.16; 'wrote:': 0.18; 'looked': 0.18; '>>>': 0.22; 'memory': 0.22; 'programming': 0.22; 'header:User-Agent:1': 0.23; 'integer': 0.24; '---': 0.24; 'certain': 0.27; 'gets': 0.27; 'header:X-Complaints-To:1': 0.27; 'van': 0.27; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'appreciated.': 0.29; 'array': 0.29; 'est': 0.30; 'mix': 0.30; "i'm": 0.30; 'work.': 0.31; 'gives': 0.31; 'code': 0.31; 'url:wiki': 0.31; 'assert': 0.31; 'lists': 0.32; 'languages': 0.32; 'problem': 0.35; 'info': 0.35; 'problem.': 0.35; 'but': 0.35; "didn't": 0.36; 'subject:?': 0.36; 'url:org': 0.36; 'list': 0.37; 'question,': 0.38; 'to:addr:python-list': 0.38; 'skip:- 10': 0.38; 'expect': 0.39; 'subject:can': 0.39; 'to:addr:python.org': 0.39; 'skip:- 60': 0.39; 'received:org': 0.40; 'how': 0.40; 'problems.': 0.60; 'solve': 0.60; 'simple': 0.61; 'protection': 0.63; 'kind': 0.63; 'skip:n 10': 0.64; 'more': 0.64; 'virus': 0.65; 'antivirus': 0.68; 'anything.': 0.68; 'hints': 0.68; 'article': 0.77; 'subject:this': 0.83; 'around,': 0.84; 'courrier': 0.84; 'determinant': 0.84; 'lying': 0.84; 'matrix.': 0.84; 'multiplying': 0.84; 'programs:': 0.84; 'albert': 0.91
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Joseph Martinot-Lagarde <joseph.martinot-lagarde@m4x.org>
Subject Re: How can this assert() ever trigger?
Date Wed, 14 May 2014 01:14:04 +0200
References <536e44c1$0$27147$e4fe514c@dreader35.news.xs4all.nl> <mailman.9917.1399914607.18130.python-list@python.org> <5371ec30$0$27133$e4fe514c@dreader35.news.xs4all.nl>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 8bit
X-Gmane-NNTP-Posting-Host gns13-1-88-122-220-146.fbx.proxad.net
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0
In-Reply-To <5371ec30$0$27133$e4fe514c@dreader35.news.xs4all.nl>
X-Antivirus avast! (VPS 140513-3, 13/05/2014), Outbound message
X-Antivirus-Status Clean
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.9982.1400022859.18130.python-list@python.org> (permalink)
Lines 78
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1400022859 news.xs4all.nl 2838 [2001:888:2000:d::a6]:43458
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:71513

Show key headers only | View raw


Le 13/05/2014 11:56, Albert van der Horst a écrit :
> In article <mailman.9917.1399914607.18130.python-list@python.org>,
> Joseph Martinot-Lagarde  <joseph.martinot-lagarde@m4x.org> wrote:
>> Le 10/05/2014 17:24, Albert van der Horst a écrit :
>>> I have the following code for calculating the determinant of
>>> a matrix. It works inasfar that it gives the same result as an
>>> octave program on a same matrix.
>>>
>>> / ----------------------------------------------------------------
>>>
>>> def determinant( mat ):
> ..
>>>       result = lastr[jx]
>>>       assert(result<>0.)
> ...
>>>           assert(result<>0.)
>>>           nom *= result   # Compenstate for multiplying a row.
> ...
>>>       assert(nom<>0.)
> ..
>>>
>>> /-----------------------------------------
>>>
>>> Now on some matrices the assert triggers, meaning that nom is zero.
>>> How can that ever happen? mon start out as 1. and gets multiplied
>>> with a number that is asserted to be not zero.
>>>
>>> Any hints appreciated.
>>>
>>> Groetjes Albert
>>>
>> I know it's not the question, but if you want a replacement for octave
>> did you try numpy (and scipy) ? The determinant would be computer faster
>> and with less memory than with your function.
>
> I'm using several programming languages in a mix to solve Euler problems.
> This is about learning how octave compares to python for a certain kind of
> problem as anything.
> The determinant program I had lying around, but it was infinite precision
> with integer only arithmetic. Then I made a simple modification and got
> mad because I didn't understand why it didn't work.
>
> I have used numpy and its det before, but I find it difficult to
> remember how to create a matrix in numpy. This is the kind of thing
> that is hard to find in the docs. Now I looked it up in my old
> programs: you start a matrix with the zeroes() function.
>
> I expect the built in determinant of octave to be on a par with corresponding
> python libraries.
>
>>
>> ---
>
> Groetjes Albert
>
>
>
You can use numpy.zeros(), but you can also use the same list of lists 
that you use for your problem.

Transform a list of lists into a numpy array:
 >>> np.asarray([[1, 2],[3, 4]])
array([[1, 2],
        [3, 4]])

Use a numpy function directly on a list of lists (works for must numpy 
functions):
 >>> np.linalg.det([[1, 2],[3, 4]])
-2.0000000000000004

More info on array creation: 
http://wiki.scipy.org/Tentative_NumPy_Tutorial#head-d3f8e5fe9b903f3c3b2a5c0dfceb60d71602cf93

---
Ce courrier électronique ne contient aucun virus ou logiciel malveillant parce que la protection avast! Antivirus est active.
http://www.avast.com

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

How can this assert() ever trigger? albert@spenarnc.xs4all.nl (Albert van der Horst) - 2014-05-10 15:24 +0000
  Re: How can this assert() ever trigger? Peter Otten <__peter__@web.de> - 2014-05-10 17:50 +0200
  Re: How can this assert() ever trigger? Ethan Furman <ethan@stoneleaf.us> - 2014-05-10 08:35 -0700
  Re: How can this assert() ever trigger? Gary Herron <gary.herron@islandtraining.com> - 2014-05-10 08:48 -0700
  Re: How can this assert() ever trigger? Alain Ketterlin <alain@dpt-info.u-strasbg.fr> - 2014-05-10 17:56 +0200
    Re: How can this assert() ever trigger? albert@spenarnc.xs4all.nl (Albert van der Horst) - 2014-05-10 16:39 +0000
  Re: How can this assert() ever trigger? Joseph Martinot-Lagarde <joseph.martinot-lagarde@m4x.org> - 2014-05-12 19:05 +0200
    Re: How can this assert() ever trigger? albert@spenarnc.xs4all.nl (Albert van der Horst) - 2014-05-13 09:56 +0000
      Re: How can this assert() ever trigger? Joseph Martinot-Lagarde <joseph.martinot-lagarde@m4x.org> - 2014-05-14 01:14 +0200

csiph-web