Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!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.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'initialize': 0.05; 'much!': 0.05; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'etc...': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:array': 0.16; 'string': 0.17; 'wrote:': 0.17; 'variables': 0.17; 'subject:skip:i 10': 0.22; 'header:In-Reply- To:1': 0.25; 'header:User-Agent:1': 0.26; 'header:X-Complaints- To:1': 0.28; 'subject:/': 0.28; 'subject:like': 0.29; 'array': 0.29; 'help,': 0.32; 'could': 0.32; 'to:addr:python-list': 0.33; 'received:org': 0.36; 'thank': 0.36; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'subject:...': 0.63; 'skip:n 10': 0.63; 'received:12': 0.81 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Emile van Sebille Subject: Re: numpy - 2D matrix/array - initialization like in Matlab... Date: Mon, 15 Oct 2012 14:52:26 -0700 References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: 12.184.110.78 User-Agent: Thunderbird 2.0.0.24 (Windows/20100228) In-Reply-To: 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: 25 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1350337892 news.xs4all.nl 6946 [2001:888:2000:d::a6]:36740 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:31345 someone wrote: > How to initialize my array directly using variables ? > > It could also be that I wanted: > > test11 = 1 > test12 = 1.5 > test13 = 2 > test21 = 0 > test22 = 5 > > Dx = numpy.matrix('test11 test12 test13; test21 test22 -0.5; 0 -0.5 1.5') > > Etc... for many variables... > > Appreciate ANY help, thank you very much! You could use string interpolation: Dx = numpy.matrix('%s %s %s; %s %s -0.5; 0 -0.5 1.5' % (test11 test12 test13 test21 test22)) Emile