Skip to content Skip to sidebar Skip to footer

Numpy Stack To 2d Array, Select By Index From Another Stack

I have two sets of classifications (Lc1 and Lc2) and two sets of probabilities (Lp1 and Lp2). Lp1 is the set of probabilities that describes the classification likelihood in Lc1.

Solution 1:

In your case ìndex refers to the first dimension, and you need to create ascending indices for the other dimensions.

If you write them manually it looks like

dim_1 = np.array([[0, 0],
                  [1, 1]])


dim_2 = np.array([[0, 1],
                  [0, 1]])

print(c_stack[index, dim_1, dim_2])

You can create them automatically using np.arange, np.vstack, np.hstack and np.tile, np.column_stack. There are several ways to do this.

E.g.

x = np.arange(5)

a = np.tile(x, (5, 1))
b = np.column_stack(tuple(a))
print(a)
print(b)

This technique in Numpy is called "Integer array indexing".


Post a Comment for "Numpy Stack To 2d Array, Select By Index From Another Stack"