Message from discussion
NumPy array to Table or Matrix
Received: by 10.205.132.133 with SMTP id hu5mr1021895bkc.4.1323629439435;
Sun, 11 Dec 2011 10:50:39 -0800 (PST)
X-BeenThere: pyo-discuss@googlegroups.com
Received: by 10.204.200.144 with SMTP id ew16ls17282484bkb.2.gmail; Sun, 11
Dec 2011 10:50:38 -0800 (PST)
Received: by 10.205.131.9 with SMTP id ho9mr1023289bkc.6.1323629438807;
Sun, 11 Dec 2011 10:50:38 -0800 (PST)
Received: by 10.205.131.9 with SMTP id ho9mr1023288bkc.6.1323629438782;
Sun, 11 Dec 2011 10:50:38 -0800 (PST)
Return-Path: <belan...@gmail.com>
Received: from mail-bw0-f44.google.com (mail-bw0-f44.google.com [209.85.214.44])
by gmr-mx.google.com with ESMTPS id j1si10176314bky.2.2011.12.11.10.50.38
(version=TLSv1/SSLv3 cipher=OTHER);
Sun, 11 Dec 2011 10:50:38 -0800 (PST)
Received-SPF: pass (google.com: domain of belan...@gmail.com designates 209.85.214.44 as permitted sender) client-ip=209.85.214.44;
Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of belan...@gmail.com designates 209.85.214.44 as permitted sender) smtp.mail=belan...@gmail.com; dkim=pass (test mode) header...@gmail.com
Received: by bkbzs8 with SMTP id zs8so5152496bkb.31
for <pyo-discuss@googlegroups.com>; Sun, 11 Dec 2011 10:50:38 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=gamma;
h=mime-version:in-reply-to:references:date:message-id:subject:from:to
:content-type;
bh=ZSqjBrXx+kGuS6jOjY+uHk/A4Lbj02UlcmuiDq3ZxR4=;
b=lq2a39MPXQ2AY4vUjFQXFFSRiAtaddQ3JWFWdGQZ+nTXWQKHHUr4krmBdBbw//ZMGc
T/+W1W8wmIFv2+/ibx33IsSXGrkrE8MbWlShN5459mQejJGLqpN3zT1RiLlm08ByiVci
YJ7r5/U7iAwdmhBkfOuSV8ny70j7TYEV7I+tk=
MIME-Version: 1.0
Received: by 10.204.155.150 with SMTP id s22mr2090046bkw.140.1323629438543;
Sun, 11 Dec 2011 10:50:38 -0800 (PST)
Received: by 10.204.185.75 with HTTP; Sun, 11 Dec 2011 10:50:38 -0800 (PST)
In-Reply-To: <30792770.432.1323623225582.JavaMail.geo-discussion-forums@yqko12>
References: <30792770.432.1323623225582.JavaMail.geo-discussion-forums@yqko12>
Date: Sun, 11 Dec 2011 13:50:38 -0500
Message-ID: <CAMXBGhTREpdx0R0rbbz6JGbKf2+09C4Y2dJ0yTNowQn605N...@mail.gmail.com>
Subject: Re: [pyo-discuss] NumPy array to Table or Matrix
From: =?ISO-8859-1?Q?Olivier_B=E9langer?= <belan...@gmail.com>
To: pyo-discuss@googlegroups.com
Content-Type: multipart/alternative; boundary=0015175923267fa60f04b3d57e50
--0015175923267fa60f04b3d57e50
Content-Type: text/plain; charset=ISO-8859-1
Hi Lennart,
There is no direct support for numpy array in pyo (it's in my plan to
implement it). The most straight-forward way to do this by now is to
convert your array to a list and give it to the "init" argument of a
DataTable or a NewMatrix object:
##################################################################################
from pyo import *
import numpy as np
import math
s = Server().boot()
size = 512
arr = np.array([math.sin(2 * math.pi * i / size) for i in range(size)])
t = DataTable(size, init=arr.tolist())
t.view()
size = 256
arr2 = np.array([[math.sin(2 * math.pi * j / size + math.sin(i/16.0)) for j
in range(size)] for i in range(size)])
m = NewMatrix(size, size, arr2.tolist())
m.view()
s.gui(locals())
##################################################################################
Olivier
2011/12/11 Lennart Hilbert <lennart.hilb...@googlemail.com>
> Hi,
>
> I am looking for a way to write the values of a NumPy float array into a
> pyo Table or Matrix object in a single, whole array operation.
>
> I assume I could use a loop over each element of the NumPy array. In each
> loop iteration I can use the put(value,x,y) method to the Matrix object to
> store the values one by one.
>
> But, that seems very inefficient to me. Is there a straight-forward way to
> assign a whole NumPy array to a pyo Matrix or Table in a single, whole
> array operation?
>
> Any comments appreciated. I did not find anything on this topic in the
> documentation and in this discussion group.
>
>
> Many thanks,
>
> Lennart
>
--0015175923267fa60f04b3d57e50
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Hi Lennart,<br><br>There is no direct support for numpy array in pyo (it=
9;s in my plan to implement it). The most straight-forward way to do this b=
y now is to convert your array to a list and give it to the "init"=
; argument of a DataTable or a NewMatrix object:<br>
<br>#######################################################################=
###########<br>from pyo import *<br>import numpy as np<br>import math<br><b=
r>s =3D Server().boot()<br><br>size =3D 512<br>arr =3D np.array([math.sin(2=
* math.pi * i / size) for i in range(size)])<br>
t =3D DataTable(size, init=3Darr.tolist())<br>t.view()<br><br>size =3D 256<=
br>arr2 =3D np.array([[math.sin(2 * math.pi * j / size + math.sin(i/16.0)) =
for j in range(size)] for i in range(size)])<br>m =3D NewMatrix(size, size,=
arr2.tolist())<br>
m.view()<br><br>s.gui(locals())<br>########################################=
##########################################<br><br>Olivier<br><br><div class=
=3D"gmail_quote">2011/12/11 Lennart Hilbert <span dir=3D"ltr"><<a href=
=3D"mailto:lennart.hilb...@googlemail.com">lennart.hilb...@googlemail.com</=
a>></span><br>
<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex">Hi,<br><br>I am looking for a way to write t=
he values of a NumPy float array into a pyo Table or Matrix object in a sin=
gle, whole array operation.<br>
<br>I assume I could use a loop over each element of the NumPy array. In ea=
ch loop iteration I can use the put(value,x,y) method to the Matrix object =
to store the values one by one.<br><br>But, that seems very inefficient to =
me. Is there a straight-forward way to assign a whole NumPy array to a pyo =
Matrix or Table in a single, whole array operation?<br>
<br>Any comments appreciated. I did not find anything on this topic in the =
documentation and in this discussion group.<br><pre><br></pre>Many thanks,<=
br><font color=3D"#888888"><br>Lennart<br></font></blockquote></div><br>
--0015175923267fa60f04b3d57e50--