Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.007 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'wrapper': 0.07; 'python': 0.08; 'function:': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'underlying': 0.09; '"int': 0.16; 'enigma': 0.16; 'kern': 0.16; 'numpy': 0.16; 'subject:array': 0.16; 'subject:ndarray': 0.16; 'wrote:': 0.18; 'memory': 0.21; 'trying': 0.21; 'header:In-Reply-To:1': 0.22; 'url:doc': 0.25; 'function': 0.27; 'pass': 0.29; 'explicitly': 0.29; 'interpret': 0.29; 'pm,': 0.29; 'array': 0.30; 'list:': 0.31; 'list': 0.32; 'pretty': 0.32; 'header:User-Agent:1': 0.33; 'header:X-Complaints- To:1': 0.33; 'to:addr:python-list': 0.34; 'copied': 0.34; 'declared': 0.34; 'list.': 0.35; 'similar': 0.36; 'using': 0.38; 'purposes': 0.38; 'received:org': 0.38; 'url:docs': 0.39; 'mailing': 0.39; "i'd": 0.39; 'url:org': 0.39; 'to:addr:python.org': 0.40; 'world': 0.62; 'received:86': 0.63; 'our': 0.64; 'accepts': 0.64; 'believe': 0.65; 'below:': 0.80; 'laid': 0.84; 'url:array': 0.84; 'url:reference': 0.84; 'eco': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Robert Kern Subject: Re: Numpy ndarray to C array Date: Thu, 08 Dec 2011 21:31:39 +0000 References: <4ee07a56-50f9-4784-a52e-31553f0d3dc8@v29g2000yqv.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: cpc24-cmbg15-2-0-cust204.5-4.cable.virginmedia.com User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:8.0) Gecko/20111105 Thunderbird/8.0 In-Reply-To: <4ee07a56-50f9-4784-a52e-31553f0d3dc8@v29g2000yqv.googlegroups.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 28 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1323379917 news.xs4all.nl 6899 [2001:888:2000:d::a6]:43331 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:16878 On 12/8/11 7:56 PM, Enrico wrote: > I am trying to pass a multi-dimensional ndarray to C as a multi- > dimensional C array for the purposes of passing it to mathematica. > They already have a wrapper for a 1-D Python list. where the list is > copied to "list". Shown below: > I would like to create a similar wrapper which accepts an ndarray and > provides the array laid out in memory like a C array declared > explicitly as "int a[m][n]...". I also need to pass the length of the > array at each level i as dim[i]. Since this is pretty much the only > function I plan to wrap, I'd like to avoid using boost, swig, etc. You will find it better to ask numpy questions on the numpy mailing list: http://www.scipy.org/Mailing_Lists In this case, you are looking for the PyArray_AsCArray() function: http://docs.scipy.org/doc/numpy/reference/c-api.array.html#PyArray_AsCArray -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco