Issue
I have a 2D array composed of times on the left and masses on the right. I want to filter the array to 10 known values of 1 year. So my expected/desired output is the following:
array([[ 3.64990e+02, -4.09452e+06],
[ 7.29730e+02, -5.45551e+06],
[ 1.09450e+03, -6.39009e+06],
[ 1.45910e+03, -7.15813e+06],
[ 1.82380e+03, -7.87166e+06],
[ 2.18860e+03, -8.58857e+06],
[ 2.55340e+03, -9.33691e+06],
[ 2.91820e+03, -1.01254e+07],
[ 3.28310e+03, -1.09508e+07],
[ 3.64790e+03, -1.18056e+07]])
As you can see, the numbers on the left are 1, 2, 3,..., 10 years in days. I want the numbers on the right which correspond to each of these years. Here is an example of what the data is like at the start and end of the array:
n = con = np.stack((times, mass), axis=1)
print(n)
[[ 2.77990e-01 -3.58090e+01]
[ 5.55970e-01 -9.10160e+01]
[ 8.33960e-01 -1.70890e+02]
...
[ 3.64960e+03 -1.18096e+07]
[ 3.64990e+03 -1.18103e+07]
[ 3.65000e+03 -1.18106e+07]
Here is how I tried to index it for the desired values and it did not work:
for ti, mi in n:
for mi in [365,365*2,365*3,365*4,365*5,365*6,365*7,365*8,365*9,365*10]:
print(ti,mi)
365 -35.809
730 -35.809
1095 -35.809
1460 -35.809
1825 -35.809
2190 -35.809
2555 -35.809
2920 -35.809
3285 -35.809
3650 -35.809
365 -91.016
730 -91.016
1095 -91.016
1460 -91.016
1825 -91.016
2190 -91.016
2555 -91.016
2920 -91.016
3285 -91.016
3650 -91.016
365 -170.89
730 -170.89
1095 -170.89
1460 -170.89
1825 -170.89
2190 -170.89
2555 -170.89
2920 -170.89
3285 -170.89
3650 -170.89
365 -282.73
It starts repeating and the values on the right are incorrect. I'm not a programmer, so I'm not sure what I'm doing wrong.
Solution
Per my understanding you have time
and masses
as 2d array
and you want to filter the values based on time
which is your first element
in every sub-array
then below code should work.
num_of_years = 10
for ti, mi in n:
if ti in list(range(365,365*(num_of_years+1),365)):
print(ti,mi)
Hope this helps !
Answered By - Abhi
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.