Home > Software design >  How to devide each value of a column of a numpy array by a value
How to devide each value of a column of a numpy array by a value

Time:11-24

I have a numpy array Y_test_traInv_RMSE with 3 columns, as you can see in the screenshotenter image description here

Now I would like to devide the each value of the third column (index 2) by the value 4700. I tried the following commands but none of them helped:

Y_test_traInv_RMSE [2] [:] = Y_test_traInv_RMSE [2] [:] /4700
Y_test_traInv_RMSE [:] [2] = Y_test_traInv_RMSE [:] [2] /4700
Y_test_traInv_RMSE [:,2] = Y_test_traInv_RMSE [:,2] /4700
Y_test_traInv_RMSE [2,:] = Y_test_traInv_RMSE [2,:] /4700

Any idea how I can do that? I just want to have every value only of the column with index 2 divided by 4700.

CodePudding user response:

Your third option should work. At least it works with this test data, so maybe you have another issue.

test = np.arange(30).astype(float).reshape(10, 3)
print(test)
test[:,2] = test[:,2] / 4700
print(test)
  • Related