I have been looking for a solution to this for a while. I am trying to use as few loops in my code as possible, so I've been trying to set slices of the numpy arrays instead.
I have a large array of size (s, s, s, s), but you can think of it as storing 2d sxs arrays inside of each spot in a larger sxs array.
I want to store, in each spot in the larger array, a small sxs full of the scalar value from other_array[location inside big array].
For example, let's imagine a big 2x2 array containing 2x2 arrays at each spot. At the spot (0,0), I need to create a 2x2 array full of other_array[(0,0)] values.
What is a simple way to do this using array slicing? Here is what I want to simplify:
pair_values = np.zeros((num_s, num_s, num_s, num_s))
for x in range(num_s):
for y in range(num_s):
pair_values[x,y] = np.full((num_s, num_s), values[(x, y)])
Right now this is my code, but I have no idea what to put for the index of my "values" array:
pair_values = np.zeros((num_s, num_s, num_s, num_s))
pair_values[:, :] = np.full((num_s, num_s), values[?])
Please let me know if this is confusingly explained and I will try to rephrase. Essentially the question is how to use each index when slicing with (:).