How to devide each value of a column of a numpy array by a value

Question:

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.

Asked By: PeterBe

||

Answers:

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)
Answered By: steflbert
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.