ValueError: Integers to negative integer powers are not allowed.

Contents of articles

The cause of the problem is solved

problem

Run the following code to prompt for an error

rowsum = np.array([1,2,3])
r_inv = np.power(rowsum, -1)

ValueError: Integers to negative integer powers are not allowed.

reason

The data type of rowsum is integer, not floating-point number. Only floating-point number can perform power operation

solve

rowsum = np.array([1,2,3], dtype=np.float32)
r_inv = np.power(rowsum, -1)

Read More: