[nmag-users]

65 views
Skip to first unread message

Yuliang Liu

unread,
Apr 23, 2014, 10:59:06 PM4/23/14
to nmag-...@lists.soton.ac.uk
Hi, all

I just contact nmag software package. After reading manual, I have a question about simple moving write-head example.

In the code, I can not understand a statement.

def H(r):
x, y, z = [ri/1e-9 - ci for ri, ci in zip(r, center)]
factor = H_amplitude*math.exp(-(x*x + y*y + z*z)/(width*width))
return [0, 0, -factor]

Can someone help me to explain the highlighted statement? Thank you very much.

Regards,
Yuliang Liu
CML
University of California, Berkeley

Oleksandr Pylypovskyi

unread,
Apr 24, 2014, 2:54:44 AM4/24/14
to Yuliang Liu, nmag-...@lists.soton.ac.uk
Hi,

Expression zip(r, center) generates list (array) of pairs [(1, 10), (2, 20), (3, 30)] if r=[1, 2, 3] and center=[10,20,30], for example. 
The right side generates a list where each element generates by equation "ri/1e-9 - ci". Values of variables ri and ci are taken in from the list, generated by zip(r, center). Expression "for ri, ci in zip(r, center)" allows to iterate over each pair in zip(r, center) where the fisrt element in pair assigns to ri, and the second to ci. 
Because lists r and center contain 3 values, the resulting "zipped" list also contain 3 pairs and the expression [ri/1e-9 - ci for ir, ci in zip(r, center)] also generates three values. Thus, result can be assigned to three variables x, y, z directly. 

In pseudocode:
r = [1, 2, 3];
center = [10, 20, 30];
For i = 1, 2, 3 do
   res[i] = r[i]/1e-9 - center[i]
x = res[1]; 
y = res[2];
z = res[3];
--
Best wishes,
Oleksandr Pylypovskyi aka Engraver

Yuliang Liu

unread,
Apr 24, 2014, 3:22:51 AM4/24/14
to Oleksandr Pylypovskyi, luyan...@gmail.com, nmag-...@lists.soton.ac.uk
Thank you very much for the detailed explanation.

Dedi Setiabudidaya

unread,
Oct 9, 2014, 2:36:00 AM10/9/14
to nmag-...@lists.soton.ac.uk
Dear All,
My name is Dedi Setiabudidaya; I work at the Sriwijaya University, South Sumatra, Indonesia.
I am interested in using nmag for my research. Now, I am writing a proposal for international collaboration to my university for year 2015 (can be extended up to 2017). Is anybody interested  ? Thank you.

Regards,

Dedi Setiabudidaya

Head of The Study Program
Doctoral Program in Mathematics and Natural Sciences
Graduate School
Sriwijaya University,
South Sumatra Indonesia 



Date: Thu, 24 Apr 2014 09:54:44 +0300
Subject: Re: [nmag-users]
From: o.pyly...@gmail.com
To: liuyuli...@gmail.com
CC: nmag-...@lists.soton.ac.uk
Reply all
Reply to author
Forward
0 new messages