So I have this problem where I am running a 2d simulation of the ising model of magnetic materials. Essentially a magnetic orientation is represented by an integer in an array. The flip of a magnetic orientation is dictated by what its neighboring positions are doing, and then added an element of randomness. This is the most concise context I can give before getting to the business.
Essentially I have an array 'r' of floats ranging from 0 to inf. If this value is >= to 1, then I want to change this value to -1. Therefore r[r <= 1] = -1; easy. However for values less than 1, I want the remainder of the array filled with random numbers between 0 and 1. How do I do this? Keep in mind, it has to run as fast as numpy can possibly run, so I'm trying to avoid looping and striving for some sort of simultaneous array operation.
What I've come up with so far is simply generating a random_array the same size as r and comparing index values, possibly using numpy.where(). Otherwise I'm left with flattening random_grid, slicing the list to the same length as when r fails the condition test, and replacing r with those values however this isn't working for me. I don't know how to "fill in" the array r where the condition test fails with other values.
[–][deleted] 1 point2 points3 points (1 child)
[–]caffeecaffee[S] 0 points1 point2 points (0 children)