Note that there are some explanatory texts on larger screens.

plurals
  1. POProjecting Coordinates in Numpy array
    primarykey
    data
    text
    <p>So I have come across a rather large bottle neck in my software. I have a set of co-ordinates in <code>cords</code> where each row corresponds to <code>X,Y,Z</code> co-ordinates. Each co-ordinate in <code>cords</code> has a defined area in <code>atom_proj</code>. The <code>atoms</code> variable corresponds to the <code>cords</code> variable and provides the key to the <code>atom_proj</code>.</p> <p>I project the co-ordinates onto the <code>grid</code> array then rotate and repeat until the number of rotations is satisfied. I only project the X and Z co-ordinates ignoring the Y.</p> <p>I have simplified version of my code below. The code runs relatively quick for small co-ordinate sets and number of rotations. But can take a long time if both co-ordinate set and rotation list is large. The number of co-ordinates can vary from a few hundred to tens of thousands. I project the area on the <code>grid</code> over a number or rotations to produce a heat map. An example of the heat map for a co-ordinate set is also shown below.</p> <p><strong>Question:</strong></p> <p>(i) - How can I decrease the projection time of the co-ordinates onto the matrix</p> <p>(ii) - Is there a more pythonic way of applying the co-ordinate area to the <code>grid</code> rather than array splicing?</p> <pre><code>import numpy as np cords = np.array([[5,4,5],[5,4,3],[6,4,6]]) atoms = np.array([['C'],['H'],['C']]) atom_proj = {'H':np.array([[0,0,0,0,0],[0,0,1,0,0],[0,1,1,1,0],[0,0,1,0,0],[0,0,0,0,0]]),'C':np.array([[0,0,0,0,0,0,0],[0,0,0,0,0,0,0],[0,0,1,1,1,0,0],[0,0,1,1,1,0,0],[0,0,1,1,1,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0]])} grid = np.zeros((10,10)) for rot in xrange(1,10): # This for loop would contain a list of list of rotations to apply which are calculated before hand. # apply rotation for values in zip(cords, atoms): atom_shape = np.shape(atom_proj[values[1][0]]) rad = (atom_shape[0]-1)/2 grid[values[0][2]-rad:values[0][2]+rad+1,values[0][0]-rad:values[0][0]+rad+1] += atom_proj[values[1][0]] print grid </code></pre> <p>Heat map: <img src="https://i.stack.imgur.com/B1W0z.png" alt="enter image description here"></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload