Python Forum
Trying to replace for loops with numpy
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trying to replace for loops with numpy
#3
Thank you for your reply! I was trying to symplify everything while explaining the problem but it lacks a some important details.

So as I mentioned in the beguining, the program computes the distances between a ball and the Floor through 11 time steps and finds the minimum distance. It does so by comparing the distances between all elements of each part (ball which is the first part or el1, and floor, the second part, el2), but the parts have a different number of elements each (2048 for the ball and 900 for the floor). These elements are basicaly the average of node coordenates in a certain area of the part. I'm using the loop "for i in range(lp1)" (part 1) so that it starts with the first element of that first part and then a second loop, that compares the first element of the first part to all elements of the second part, and them goes forward repeating the same steps for all elements of part 1. In that way, the code is comparing the distance between all the elements of each part and finding their minimum (which would be a case of "contact").

So, other than using an alternative to the append command, is there a way to replace the for loops that goes around each individual element at a time? Basicaly what im trying to do is to compare 2048 11x3 matrices to 900 also 11x3 matrices, without having to use the for loops to deal with the difference in the number of matrices.

Hope this helps clarifying what I am trying to say! I'm sorry for my vocabulary regarding python terms, I have just started using the program so I'm still not familiar with them.
Reply


Messages In This Thread
RE: Trying to replace for loops with numpy - by vspoloni - Jul-31-2019, 12:43 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Numpy] How to store different data type in one numpy array? water 7 633 Mar-26-2024, 02:18 PM
Last Post: snippsat
  Numpy returns "TypeError: unsupported operand type(s) for *: 'numpy.ufunc' and 'int'" kalle 2 2,642 Jul-19-2022, 06:31 AM
Last Post: paul18fr
  replace sets of values in an array without using loops paul18fr 7 1,763 Jun-20-2022, 08:15 PM
Last Post: paul18fr
  "erlarge" a numpy-matrix to numpy-array PhysChem 2 3,008 Apr-09-2019, 04:54 PM
Last Post: PhysChem

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020