Python numpy array data processing
I have 2 csv files with 16 columns and 146 rows. I am trying to do the following (this is not actual data):
a = [1, 2, 3, 4, 5, 6]
b = [10, 20, 30, 40, 50, 60]
final output of the script intended:
x = [ 11, 22, 33, 22, 22.5, 33] # basically the last half of the array needs to be divided by 2
I've tried the following code:
import csv
import numpy as np
import sys
data = np.genfromtxt('./test1.csv', dtype=float, delimiter=',')
data_sys = np.genfromtxt('.test2.csv', dtype=float, delimiter=',')
z = np.add (data, data_sys)
np.savetxt("new_before_avg.csv", z, delimiter= ',')
z[:,8:15] = z[:,8:15]/2
np.savetxt("new_after_avg.csv"], z, delimiter= ",")
The problem is I can see the end result as expected except for the last column (column 15). It's just added, not split by 2.
I thought my indexing was correct. Please, help.
+3
source to share