1

I am trying to write a script that includes following line,

fra = struct.frac_coords

and "fra" gives following answer:

array([[ 0.01106406,  0.11554355,  0.50754736],
   [ 0.00294858,  0.24640931,  0.99887037],
   [ 0.37046412,  0.08121749,  0.9386742 ],
   [ 0.49430774,  0.07065645,  0.7479905 ],
   [ 0.6249222 ,  0.04073112,  0.56187813]])

and then I have the following line:

periodic = struct.get_sites([ 0.01106406,  0.11554355,  0.50754736], 5.95, include_index=True)

print(periodic)

So I have to input each line of the array obtained from "fra" into the "periodic" line to get the results. How can I make the lines in a way that I wouldn't need to put the lines of the array into the "periodic" commend?

Thank you.

0

2 Answers 2

1

You're in luck! There's an awesome thing called the for loop that lets you loop over each row in turn and compute the same.

fra = struct.frac_coords

for row in fra:
    periodic = struct.get_sites(row, 5.95, include_index=True) 
    print(periodic)
Sign up to request clarification or add additional context in comments.

Comments

0

I use list comprehension to do this job.

   import numpy as np
    x = np.array([[ 0.01106406,  0.11554355,  0.50754736],
       [ 0.00294858,  0.24640931,  0.99887037],
       [ 0.37046412,  0.08121749,  0.9386742 ],
       [ 0.49430774,  0.07065645,  0.7479905 ],
       [ 0.6249222 ,  0.04073112,  0.56187813]])

    def get_sites(a):
        return a*2

    [get_sites(y) for y in x]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.