I am new to python and trying to figure out, how to loop over a 2x2 matrix.
My starting point is a *.csv file, which contains a huge amount of data (10 columns with 173828 rows). Because I only need the first column (sigma_0 values) and the sixth column (date), I made a matrix called sigma_JD, which only contains these two columns:
import csv
import numpy as np
with open("C:/Users/.../03971822.csv") as input_file:
reader = csv.reader(input_file)
array = []
for row in reader:
array.append(row)
matrix = np.asmatrix(array)
idx_IN_columns = [0, 5]
sigma_JD = matrix[:, idx_IN_columns]
print(sigma_JD)
print("size sigma_JD: ", np.shape(sigma_JD))
>>> print(sigma_JD)
[['-12.42' '2451544.576']
['-12.92' '2451544.576']
['-12.45' '2451544.576']
...,
['-11.66' '2454688.389']
['-12.61' '2454688.389']
['-11.72' '2454688.389']]
>>> print("size sigma_JD: ", np.shape(sigma_JD))
size sigma_JD: (173828, 2)
Now I want to loop over the second column - the date; it is shown in a specific way, it's called "Julian Day", eg the JD values are
2451544,5 = 01/January/2000 0:00 2451545,5 = 02/January/2000 0:00 2451546,5 = 03/January/2000 0:00
The 2451544 tells the day/month/year, the decimal place tells the time.
I want to write a code, in which all the sigma_0 values are considered, which are within one day. So, the loop should work with the specific values, and not via indexing.
It should start with 2451544,5, then take all the sigma_0 values into account which are within that one day (and sums it up), and then go to the next day 2451544,5 and do the same....
I tried s.th. like this, but it doesn't work
x = 2451544.5
y = x + 1
for i in sigma_JD[:, 1]:
while x < y:
print(sigma_JD[i, 1])
break
Then I thought about creating my own function, but didn't come that far:
def select(x):
count = 2451544.5
select = []
for i in range(0, len(x[:, 1])): # loop over Julian Day
if count < count + 1:
row = []
for j in range(0, len(x[:, 0])): # loop over sigma_0 values
# take all sigma_0 values and sum it up
count += 1
return select
It would be very, very nice if someone could help me. I am working on this for days, and it really cracks me up that I don't know how to get this done.
Thanks a lot.