Applying a non aggregating function to a groupby pandas object - python

I have a dataframe (called cep) with two indexes (Cloud and Mode) and data columns. It looks like this :
The data columns are fitted to a linear function and I'm extracting the residuals to the fit in this way :
import pandas as pd
from scipy.optimize import least_squares
args = [-1, 15] # initial guess for the fit
def residuals(args, x, y):
"""
Residual with respect to a linear function
args : list with 2 arguments
x : array
y : array
"""
return args[0] * x + args[1] - y
def residual_function(df):
"""
Returns the array of the residuals
"""
return least_squares(residuals, args, loss='soft_l1', f_scale=0.5, args=(df.logP1, df.W)).fun
cep.groupby(['Cloud', 'Mode']).apply(lambda grp : residual_function(grp))
This gives the expected result :
Now is my issue : I'd like to insert those residual values each in their respective row in the original dataframe to compare them with other columns.
I checked that the returned arrays are of the right length to be inserted but so far I have no idea how to proceed.
I tried to follow tutorials, but the difference with the textbook problem here is that the function I applied does not aggregate the data. Do you have some hints?
Small sample data here :
Mode;Cloud;W;logP1
F;LMC;14,525;0,4939
F;LMC;13,4954;0,7491
F;LMC;14,5421;0,4249
F;LMC;12,033;1,0215
F;LMC;14,3422;0,5655
F;LMC;13,937;0,6072
F;LMC;13,53;0,737
F;LMC;15,2106;0,2309
F;LMC;14,0813;0,5721
F;LMC;14,5128;0,41
F;LMC;14,1059;0,5469
F;LMC;15,6032;0,1014
F;LMC;13,1088;0,8562
F;LMC;12,3528;1,0513
F;LMC;13,1629;0,8416
F;LMC;14,3114;0,4867
F;LMC;14,4013;0,498
F;LMC;13,5057;0,7131
F;LMC;14,3626;0,464
F;LMC;14,5973;0,4111
F;LMC;13,9286;0,6059
F;LMC;15,066;0,2711
F;LMC;12,7364;0,9466
F;LMC;13,3753;0,7442
F;LMC;13,9748;0,5854
F;LMC;12,8836;0,8946
F;LMC;14,4912;0,4206
F;LMC;14,4131;0,4567
F;LMC;12,183;1,1382
F;LMC;14,5492;0,3686
F;LMC;14,1482;0,5339
F;LMC;13,7062;0,7116
F;LMC;13,0731;0,8682
F;LMC;11,5609;1,353
F;LMC;13,9453;0,5551
F;LMC;14,0072;0,6715
F;LMC;13,9838;0,6021
F;LMC;13,9974;0,5562
F;LMC;14,3898;0,5069
F;LMC;14,4497;0,4433
F;LMC;14,3524;0,5064
F;LMC;12,9604;0,9134
F;LMC;12,9757;0,8548
F;LMC;14,2783;0,4927
F;LMC;13,7148;0,6758
F;LMC;14,2348;0,5142
F;LMC;12,6793;0,9415
F;LMC;14,2241;0,5738
F;LMC;14,472;0,4554
F;LMC;15,1508;0,2076
F;LMC;12,5414;1,0159
F;LMC;14,2102;0,5334
F;LMC;15,6086;0,1116
F;LMC;13,2986;0,8381
F;LMC;13,0136;0,8864
F;LMC;13,9774;0,585
F;LMC;14,4256;0,533
F;LMC;14,3582;0,4578
F;LMC;14,3258;0,4859
F;LMC;14,6646;0,3757
F;LMC;12,733;0,9901
F;LMC;14,6296;0,3839
F;LMC;14,054;0,5766
F;LMC;14,3194;0,4884
F;LMC;12,6602;0,9715
F;LMC;13,5909;0,5675
F;LMC;13,9268;0,6196
F;LMC;12,5813;0,9935
F;LMC;13,0824;0,8591
F;LMC;13,5097;0,7375
F;LMC;13,1938;0,5053
F;LMC;14,7357;0,3253
F;LMC;14,0624;0,6009
F;LMC;14,1528;0,533
F;LMC;14,6709;0,4007
F;LMC;14,2378;0,4875
F;LMC;11,951;1,2004
F;LMC;14,4555;0,4777
F;LMC;14,4001;0,4404
F;LMC;13,7707;0,6311
F;LMC;14,578;0,4175
F;LMC;15,8662;0,0159
F;LMC;14,055;0,5687
F;LMC;13,6238;0,7307
F;LMC;15,2572;0,2171
F;LMC;13,4022;0,7723
F;LMC;14,2392;0,5256
F;LMC;14,2505;0,4977
F;LMC;14,7174;0,3614
F;LMC;14,487;0,418
F;LMC;14,9309;0,3086
F;LMC;13,8352;0,6334
F;LMC;14,5598;0,41
F;LMC;14,5614;0,422
F;LMC;14,1486;0,5149
F;LMC;14,0304;0,4945
F;LMC;13,5781;0,6801
F;LMC;14,79;0,3218
F;LMC;12,376;1,0908
F;LMC;15,3215;0,2176
F;LMC;14,7264;0,3845
F;LMC;14,6276;0,4057
F;LMC;14,1712;0,5313
F;LMC;14,4153;0,483
F;LMC;12,905;0,9356
F;LMC;14,442;0,4309
F;LMC;12,8702;0,9159
F;LMC;12,8963;0,5775
F;LMC;13,8304;0,6467
F;LMC;14,4665;0,4165
F;LMC;13,0756;0,5794
F;LMC;13,841;0,6593
F;LMC;14,0924;0,5671
F;LMC;13,7546;0,6778
F;LMC;14,2828;0,5181
F;LMC;14,2424;0,5082
F;LMC;14,659;0,3989
F;LMC;13,7528;0,6768
F;LMC;13,7743;0,6368
F;LMC;13,2894;0,791
F;LMC;14,7512;0,3187
F;LMC;14,5241;0,4452
F;LMC;14,301;0,5121
F;LMC;13,334;0,7945
F;LMC;13,5052;0,7012
F;LMC;14,3664;0,4549
F;LMC;14,8614;0,3278
F;LMC;13,8612;0,582
F;LMC;14,2668;0,5158
F;LMC;14,3937;0,4457
F;LMC;14,0226;0,582
F;LMC;14,387;0,5565
F;LMC;14,3198;0,4362
F;LMC;14,4404;0,4701
F;LMC;14,2774;0,4939
F;LMC;13,7678;0,6557
F;LMC;14,3212;0,4882
F;LMC;14,6453;0,3696
F;LMC;13,9064;0,6084
F;LMC;13,5167;0,7581
F;LMC;14,1692;0,5134
F;LMC;14,6714;0,4136
F;LMC;14,4332;0,4507
F;LMC;14,705;0,3631
F;LMC;13,6728;0,496
F;LMC;15,358;0,1651
F;LMC;13,7592;0,6278
F;LMC;14,0626;0,5754
F;LMC;13,1127;0,8692
F;LMC;14,2108;0,498
F;LMC;14,4519;0,4449
F;LMC;14,0041;0,5666
F;LMC;14,157;0,5392
F;LMC;14,254;0,5245
F;LMC;15,4844;0,1838
F;LMC;14,0845;0,5626
F;LMC;13,0861;0,838
F;LMC;13,3144;0,831
F;LMC;14,2535;0,4911
F;LMC;14,0256;0,5723
F;LMC;14,3246;0,4938
F;LMC;14,4412;0,4136
F;LMC;14,1043;0,518
F;LMC;14,7512;0,3772
F;LMC;14,3982;0,5039
F;LMC;14,2701;0,5042
F;LMC;13,9166;0,5941
F;LMC;13,0324;0,837
F;LMC;13,4839;0,6331
F;LMC;13,4491;0,7443
F;LMC;14,4702;0,458
F;LMC;14,4814;0,4595
F;LMC;14,3008;0,4575
F;LMC;14,922;0,3313
F;LMC;14,6542;0,4263
F;LMC;14,5007;0,4838
F;LMC;14,4335;0,4829
F;LMC;14,4737;0,4586
F;LMC;14,2537;0,5442
F;LMC;14,038;0,5473
F;LMC;14,1413;0,5523
F;LMC;14,669;0,3505
F;LMC;12,3572;1,1033
F;LMC;13,868;0,6416
F;LMC;13,4292;0,816
F;LMC;11,6771;1,3442
F;LMC;14,5086;0,4654
F;LMC;14,3588;0,4807
F;LMC;14,6915;0,3674
F;LMC;15,6488;0,0647
F;LMC;12,4187;0,9791
F;LMC;14,1555;0,5235
F;LMC;14,5765;0,4281
F;LMC;14,3579;0,4596
F;LMC;13,0932;0,7957
F;LMC;14,4552;0,4216
F;LMC;13,2221;0,8505
F;LMC;14,4465;0,4466
F;LMC;14,2439;0,5032
F;LMC;14,9606;0,6308
F;LMC;14,4774;0,4424
F;LMC;14,1875;0,5361
F;LMC;13,3982;0,7644
F;LMC;13,0973;0,8595
F;LMC;13,8264;0,6334
F;LMC;13,9296;0,6164
F;LMC;14,5778;0,4033
F;LMC;13,579;0,726
F;LMC;14,0054;0,5779
F;LMC;14,1219;0,5451
F;LMC;14,3512;0,4808
F;LMC;14,5058;0,4199
F;LMC;14,598;0,4201
F;LMC;14,9516;0,2498
F;LMC;13,9944;0,6075
F;LMC;13,9462;0,557
F;LMC;14,2576;0,5148
F;LMC;14,9814;0,2929
F;LMC;14,3851;0,4573
F;LMC;14,3474;0,4606
F;LMC;14,4929;0,3882
F;LMC;14,5201;0,4234
F;LMC;13,7677;0,6548
F;LMC;14,3146;0,4695
F;LMC;14,2846;0,507
F;LMC;14,0967;0,5525
F;LMC;14,7976;0,3546
F;LMC;13,7497;0,6362
F;LMC;14,4647;0,4363
F;LMC;14,1924;0,5293
F;LMC;14,588;0,4089
F;LMC;13,4896;0,7329
F;LMC;14,695;0,3737
F;LMC;14,2672;0,4857
F;LMC;14,0784;0,5848
F;LMC;13,879;0,5743
F;LMC;14,2214;0,4988
F;LMC;12,922;0,8487
F;LMC;14,189;0,5238
F;LMC;13,9938;0,5713
F;LMC;14,379;0,4771
F;LMC;11,2308;1,3564
F;LMC;14,4472;0,4205
F;LMC;14,3739;0,4699
F;LMC;14,393;0,4416
F;LMC;13,9108;0,5927
F;LMC;14,0298;0,6058
F;LMC;15,1538;0,1961
F;LMC;13,0393;0,8731
F;LMC;13,7144;0,645
F;LMC;14,2682;0,487
F;LMC;14,3506;0,4927
F;LMC;14,0472;0,5619
F;LMC;15,1418;0,2506
F;LMC;13,1227;0,5998
F;LMC;13,5646;0,7193
F;LMC;14,5872;0,4357
F;LMC;14,2636;0,5007
F;LMC;13,9564;0,5599
F;LMC;12,8576;0,946
F;LMC;12,3042;1,1454
F;LMC;11,8416;1,3675
F;LMC;13,5498;0,7219
F;LMC;12,1976;1,1581
F;LMC;13,8632;0,6202
F;LMC;14,2952;0,4807
F;LMC;14,4349;0,4437
F;LMC;14,2392;0,5445
F;LMC;13,7248;0,7213
F;LMC;14,3395;0,5117
F;LMC;15,3588;0,2253
F;LMC;12,8509;0,9229
F;LMC;15,5192;0,1453
F;LMC;14,2072;0,4975
F;LMC;14,3524;0,4945
F;LMC;14,5152;0,4488
F;LMC;14,5106;0,4558
F;LMC;14,5759;0,3786
F;LMC;11,196;1,2374
F;LMC;14,3736;0,4788
F;LMC;14,1726;0,528
F;LMC;11,7899;1,1995
F;LMC;12,1062;1,1823
F;LMC;13,7113;0,6714
F;LMC;14,3512;0,4815
F;LMC;13,1016;0,8181
F;LMC;14,4968;0,562
F;LMC;12,4557;1,0671
F;LMC;14,0573;0,551
F;LMC;14,5916;0,4066
F;LMC;14,3214;0,488
F;LMC;13,5498;0,4885
F;LMC;14,4679;0,4273
F;LMC;14,2426;0,4816
F;LMC;13,5759;0,7052
F;LMC;14,0081;0,5769
F;LMC;14,0828;0,5379
F;LMC;12,4168;0,7578
F;LMC;14,1624;0,5052
F;LMC;13,8029;0,6621
F;LMC;14,1944;0,5145
F;LMC;13,7944;0,6184
F;LMC;15,0234;0,3158
F;LMC;13,0961;0,8282
F;LMC;13,976;0,5889
F;LMC;14,3236;0,4847
F;LMC;14,2618;0,4691
F;LMC;13,4528;0,7349
F;LMC;14,2846;0,507
F;LMC;14,4115;0,446
F;LMC;14,2199;0,5336
F;LMC;14,456;0,4423
F;LMC;14,2938;0,488
F;LMC;14,4109;0,4606
F;LMC;14,2599;0,497
F;LMC;13,9034;0,6384
F;LMC;13,6126;0,7075
F;LMC;14,5036;0,4218
F;LMC;14,0065;0,5741
F;LMC;14,8622;0,3404
F;LMC;14,635;0,3683
F;LMC;14,222;0,5454
F;LMC;14,1501;0,5548
F;LMC;14,0822;0,5705
F;LMC;13,5036;0,7267
F;LMC;14,5528;0,4161
F;LMC;14,3332;0,4614
F;LMC;14,1511;0,5471
F;LMC;14,6113;0,3934
F;LMC;14,2998;0,5031
F;LMC;14,1807;0,5352
F;LMC;13,5114;0,7013
F;LMC;12,2096;1,1344
F;LMC;14,3799;0,4304
F;LMC;12,4526;1,1135
F;LMC;14,5042;0,447
F;LMC;13,4594;0,7336
F;LMC;13,2066;0,8423
F;LMC;14,3734;0,4711
F;LMC;13,945;0,5953
F;LMC;12,9938;0,8969
F;LMC;13,4993;0,7034
F;LMC;13,9466;0,5678
F;LMC;14,1772;0,5077
F;LMC;13,5566;0,6949
F;LMC;14,021;0,5811
F;LMC;14,0264;0,646
F;LMC;12,0242;1,1666
F;LMC;14,3106;0,5027
F;LMC;14,9838;0,3164
F;LMC;14,1718;0,5266
F;LMC;14,2606;0,489
F;LMC;12,6479;1,0206
F;LMC;12,9768;0,8684
F;LMC;14,0837;0,5785
F;LMC;13,7944;0,6609
F;LMC;13,532;0,6911
F;LMC;14,835;0,3375
F;LMC;13,7378;0,6941
F;LMC;14,3618;0,4658
F;LMC;12,4782;1,0176
F;LMC;14,2216;0,4981
F;LMC;14,3958;0,4917
F;LMC;11,3796;1,3161
F;LMC;13,8073;0,6301
F;LMC;14,414;0,4601
F;LMC;12,4266;1,086
F;LMC;14,7974;0,3547
F;LMC;14,3369;0,5189
F;LMC;14,3202;0,4874
F;LMC;14,4614;0,4664
F;LMC;13,8344;0,6339
F;LMC;14,0452;0,5896
F;LMC;11,9134;1,161
F;LMC;14,2492;0,4891
F;LMC;14,1338;0,5139
F;LMC;14,439;0,4476
F;LMC;14,1446;0,5322
F;LMC;14,102;0,549
F;LMC;14,5043;0,4421
F;LMC;14,388;0,4511
F;LMC;12,3812;1,0331
F;LMC;14,5086;0,4294
F;LMC;13,6822;0,671
F;LMC;12,3012;1,0862
F;LMC;14,0848;0,534
F;LMC;14,3381;0,4886
F;LMC;14,5544;0,3908
F;LMC;14,216;0,5226
F;LMC;14,5028;0,4323
F;LMC;12,7769;0,9244
F;LMC;13,6262;0,6984
F;LMC;14,5276;0,4107
F;LMC;13,921;0,5835
F;LMC;14,6279;0,396
F;LMC;14,6304;0,3796
F;LMC;14,2079;0,4722
F;LMC;12,4538;1,0356
F;LMC;14,2662;0,4876
F;LMC;13,8493;0,6217
F;LMC;12,9806;0,8385
F;LMC;14,3148;0,4768
F;LMC;14,2225;0,49
F;LMC;14,3932;0,4084
F;LMC;13,6934;0,5829
F;LMC;14,1702;0,5297
F;LMC;11,7812;1,2435
F;LMC;14,2866;0,4778
F;LMC;15,2824;0,1739
F;LMC;14,451;0,4485
F;LMC;14,4842;0,4222
F;LMC;14,3422;0,449
F;LMC;14,4408;0,4435
F;LMC;12,527;1,0298
F;LMC;12,3746;1,1016
F;LMC;11,4802;1,3276
F;LMC;14,47;0,4643
F;LMC;14,1469;0,5183
F;SMC;14,423;0,4796
F;SMC;15,5626;0,2344
F;SMC;15,6889;0,236
F;SMC;15,3574;0,2926
F;SMC;15,8049;0,1015
F;SMC;12,9034;0,9993
F;SMC;14,0039;0,6867
F;SMC;15,9834;0,1812
F;SMC;15,7707;0,2028
F;SMC;15,777;0,1735
F;SMC;14,7121;0,4973
F;SMC;13,8691;0,7188
F;SMC;14,889;0,4123
F;SMC;14,5322;0,6233
F;SMC;15,6791;0,331
F;SMC;13,9406;0,7262
F;SMC;13,728;0,8514
F;SMC;15,1952;0,3583
F;SMC;16,0921;0,1397
F;SMC;15,6162;0,1532
F;SMC;15,786;0,2563
F;SMC;16,0774;0,1197
F;SMC;14,4397;0,599
F;SMC;15,8693;0,2072
F;SMC;15,6668;0,2452
F;SMC;15,1954;0,3509
F;SMC;14,1387;0,669
F;SMC;15,6928;0,2125
F;SMC;14,6266;0,5017
F;SMC;15,9557;0,1772
F;SMC;15,607;0,2501
F;SMC;15,9632;0,1629
F;SMC;15,7932;0,2325
F;SMC;15,7108;0,1534
F;SMC;13,037;0,9898
F;SMC;15,3998;0,2915
F;SMC;15,1724;0,3675
F;SMC;13,7222;0,7848
F;SMC;14,8296;0,5222
F;SMC;15,704;0,2407
F;SMC;13,5231;0,8378
F;SMC;14,4338;0,5303
F;SMC;14,6202;0,4843
F;SMC;16,2836;0,0473
F;SMC;15,6011;0,1758
F;SMC;16,0037;0,1571
F;SMC;13,9062;0,6286
F;SMC;16,0606;0,0557
F;SMC;13,2924;0,8905
F;SMC;15,9942;0,1997
F;SMC;15,7766;0,2395
F;SMC;10,8462;1,6309
F;SMC;15,956;0,1425
F;SMC;13,857;0,7079
F;SMC;15,3619;0,2696
F;SMC;14,0064;0,6903
F;SMC;15,6531;0,2602
F;SMC;14,9001;0,5001
F;SMC;14,3957;0,6156
F;SMC;15,4414;0,3174
F;SMC;15,8321;0,1822
F;SMC;16,3562;0,1385
F;SMC;15,8812;0,1651
F;SMC;15,1404;0,408
F;SMC;13,7978;0,8055
F;SMC;15,9291;0,132
F;SMC;15,0555;0,507
F;SMC;15,5766;0,2596
F;SMC;13,6006;0,8469
F;SMC;16,455;0,0629
F;SMC;15,8762;0,1072
F;SMC;16,2856;0,0768
F;SMC;15,8521;0,2129
F;SMC;15,7685;0,2374
F;SMC;16,1197;0,1043
F;SMC;16,0851;0,2333
F;SMC;15,8126;0,1777
F;SMC;14,3891;0,6065
F;SMC;14,6419;0,5446
F;SMC;15,3942;0,3101
F;SMC;15,5785;0,2494
F;SMC;15,661;0,2227
F;SMC;15,9648;0,1405
F;SMC;12,7911;1,0845
F;SMC;15,9351;0,1575
F;SMC;14,1764;0,6864
F;SMC;15,153;0,3624
F;SMC;15,9336;0,1232
F;SMC;15,0124;0,3796
F;SMC;16,1231;0,106
F;SMC;14,4362;0,5306
F;SMC;13,1883;0,8354
F;SMC;15,8972;0,1757
F;SMC;14,1612;0,7287
F;SMC;15,3792;0,2869
F;SMC;16,421;0,0329
F;SMC;14,833;0,4543
F;SMC;14,3997;0,5912
F;SMC;15,8797;0,1747
F;SMC;16,0337;0,1565
F;SMC;15,7371;0,2251
F;SMC;13,954;0,7293
F;SMC;14,1691;0,6695
F;SMC;15,6208;0,2211
F;SMC;14,3416;0,6492
F;SMC;14,6636;0,5423
F;SMC;16,0386;0,1506
F;SMC;14,6578;0,5604
F;SMC;15,6368;0,24
F;SMC;14,843;0,4738
F;SMC;14,9818;0,4869
F;SMC;12,4251;1,1641
F;SMC;15,0727;0,4671
F;SMC;14,1448;0,5949
F;SMC;15,2148;0,3644
F;SMC;15,9372;0,117
F;SMC;15,4336;0,3018
F;SMC;14,5416;0,557
F;SMC;16,4654;0,0436
F;SMC;14,934;0,5498
F;SMC;14,3896;0,695
F;SMC;15,3896;0,3492
F;SMC;15,8122;0,1602
F;SMC;13,7822;0,704
F;SMC;15,7938;0,1679
F;SMC;15,4049;0,3059
F;SMC;16,0742;0,1187
F;SMC;15,704;0,2036
F;SMC;14,9947;0,3748
F;SMC;15,1374;0,4001
F;SMC;13,2254;0,7136
F;SMC;14,3267;0,577
F;SMC;12,7772;1,0317
F;SMC;15,5302;0,3074
F;SMC;16,12;0,1395
F;SMC;15,9826;0,1873
F;SMC;15,9196;0,2025
F;SMC;15,5396;0,2888
F;SMC;14,0063;0,7543
F;SMC;14,6752;0,542
F;SMC;14,3782;0,6365
F;SMC;15,8015;0,2321
F;SMC;15,4898;0,0235
F;SMC;15,6376;0,2499
F;SMC;15,527;0,2697
F;SMC;15,2883;0,3324
F;SMC;15,1014;0,3996
F;SMC;14,435;0,5827
F;SMC;16,1522;0,0832
F;SMC;13,3787;0,8974
F;SMC;16,6258;0,0226
F;SMC;14,0421;0,8043
F;SMC;15,4764;0,2719
F;SMC;14,1377;0,6069
F;SMC;15,3654;0,3461
F;SMC;16,3063;0,0677
F;SMC;15,5912;0,2227
F;SMC;14,555;0,5143
F;SMC;16,2947;0,0824
F;SMC;15,2208;0,3488
F;SMC;16,8052;-0,0287
F;SMC;15,8592;0,1835
F;SMC;15,6349;0,2632
F;SMC;16,522;0,0581
F;SMC;15,7794;0,3351
F;SMC;16,095;0,1574
F;SMC;16,0564;0,1818
F;SMC;16,4614;0,0897
F;SMC;16,1351;0,1332
F;SMC;14,4711;0,5808
F;SMC;13,8768;0,6795
F;SMC;16,2458;0,1273
F;SMC;16,1994;0,0372
F;SMC;15,3434;0,3072
F;SMC;15,5384;0,2442
F;SMC;14,5322;0,5703
F;SMC;15,7762;0,3507
F;SMC;14,3793;0,5628
F;SMC;15,4777;0,3139
F;SMC;15,9216;0,1764
F;SMC;14,3758;0,5278
F;SMC;15,2363;0,3313
F;SMC;14,3224;0,3258
F;SMC;15,2266;0,3656
F;SMC;15,6305;0,174
F;SMC;14,046;0,7832
F;SMC;14,8704;0,507
F;SMC;16,0267;0,2357
F;SMC;16,0671;0,154
F;SMC;13,8434;0,6901
F;SMC;14,4167;0,5992
F;SMC;15,9808;0,125
F;SMC;16,0696;0,1131
F;SMC;15,166;0,166
F;SMC;14,1023;0,6447
F;SMC;13,9666;0,6979
F;SMC;15,64;0,2577
F;SMC;15,6974;0,2429
F;SMC;15,1257;0,3877
F;SMC;15,186;0,3295
F;SMC;14,87;0,4651
F;SMC;16,0943;0,1807
F;SMC;15,7421;0,1809
F;SMC;14,6085;0,5253
F;SMC;14,6912;0,4777
F;SMC;14,1322;0,71
F;SMC;15,3319;0,2937
F;SMC;14,9283;0,4639
F;SMC;15,3753;0,2732
F;SMC;15,0886;0,3989
F;SMC;15,3778;0,3028
F;SMC;16,4933;0,0274
F;SMC;14,7944;0,4336
F;SMC;13,7806;0,7397
F;SMC;14,1895;0,6325
F;SMC;15,947;0,1084
F;SMC;15,9606;0,1665
F;SMC;15,417;0,0976
F;SMC;15,2905;0,3652
F;SMC;14,7712;0,4453
F;SMC;14,6692;0,5412
F;SMC;16,1936;0,0286
F;SMC;15,6136;0,2097
F;SMC;15,8061;0,078
F;SMC;15,3243;0,3385
F;SMC;15,2366;0,3669
F;SMC;16,1653;0,0573
F;SMC;15,916;0,1591
F;SMC;15,2422;0,3216
F;SMC;12,2583;1,2107
F;SMC;15,6361;0,1766
F;SMC;16,0818;0,1771
F;SMC;15,6966;0,2147
F;SMC;16,193;0,0657
F;SMC;14,8256;0,4574
F;SMC;15,7214;0,2185
F;SMC;15,5803;0,2725
F;SMC;14,7322;0,4754
F;SMC;15,8964;0,1898
F;SMC;14,5428;0,4732
F;SMC;16,1362;0,1396
F;SMC;16,2832;0,0473
F;SMC;15,6508;0,2232
F;SMC;14,725;0,4998
F;SMC;16,1585;0,1106
F;SMC;15,2284;0,3727
F;SMC;15,1728;0,3718
F;SMC;14,5354;0,5431
F;SMC;15,8224;0,1256
F;SMC;15,5462;0,2633
F;SMC;14,942;0,455
F;SMC;16,02;0,1426
F;SMC;15,2292;0,2965
F;SMC;14,6639;0,4402
F;SMC;14,887;0,4365
F;SMC;15,8288;0,1924
F;SMC;14,4903;0,5274
F;SMC;15,9464;0,1638
F;SMC;15,8069;0,1999
F;SMC;14,9924;0,3985
F;SMC;15,6917;0,1355
F;SMC;15,5414;0,1628
F;SMC;15,6168;0,2157
F;SMC;15,8006;0,177
F;SMC;14,9294;0,4732
F;SMC;14,5272;0,599
F;SMC;15,7318;0,2691
F;SMC;14,5181;0,5782
F;SMC;15,8524;0,2074
F;SMC;13,773;0,747
F;SMC;15,7608;0,1586
F;SMC;13,947;0,688
F;SMC;14,9774;0,4224
F;SMC;14,5288;0,4912
F;SMC;12,4944;1,2355
F;SMC;13,8683;0,6944
F;SMC;15,7118;0,186
F;SMC;15,7392;0,2081
F;SMC;12,292;1,1395
F;SMC;14,7918;0,4632
F;SMC;15,4428;0,3367
F;SMC;14,7542;0,4279
F;SMC;15,2914;0,3575
F;SMC;14,7332;0,4836
F;SMC;14,566;0,5553
F;SMC;15,9406;0,1167
F;SMC;15,6304;0,2296
F;SMC;14,0478;0,7063
F;SMC;15,5402;0,2821
F;SMC;15,6019;0,2443
F;SMC;15,6554;0,1979
F;SMC;14,7736;0,1631
F;SMC;16,1684;0,119
F;SMC;14,5113;0,5073
F;SMC;15,5466;0,134
F;SMC;15,1128;0,3919
F;SMC;13,4782;0,8109
F;SMC;15,8534;0,2208
F;SMC;13,1824;0,9072
F;SMC;15,8466;0,1901
1;LMC;13,9452;0,4076
1;LMC;14,3302;0,3149
1;LMC;12,9682;0,6984
1;LMC;15,0586;0,1023
1;LMC;14,328;0,304
1;LMC;15,024;0,0882
1;LMC;14,0594;0,3924
1;LMC;17,2026;-0,5304
1;LMC;14,327;0,3192
1;LMC;13,8748;0,4361
1;LMC;17,155;-0,4783
1;LMC;14,3154;0,3197
1;LMC;14,3376;0,2943
1;LMC;14,462;0,3461
1;LMC;14,139;0,3647
1;LMC;16,764;-0,4451
1;LMC;15,1618;0,1008
1;LMC;14,2229;0,3328
1;LMC;13,8046;0,4946
1;LMC;14,4268;0,2703
1;LMC;15,5032;-0,0368
1;LMC;15,9052;-0,1647
1;LMC;13,908;0,4434
1;LMC;14,3352;0,2986
1;LMC;13,6286;0,5326
1;LMC;13,7934;0,4842
1;LMC;14,3979;0,2817
1;LMC;14,0496;0,4238
1;LMC;14,4368;0,2939
1;LMC;14,3242;0,3164
1;LMC;12,6825;0,7719
1;LMC;13,846;0,4483
1;LMC;14,5746;0,2727
1;LMC;14,5171;0,2641
1;LMC;14,9218;0,1209
1;LMC;14,2248;0,3411
1;LMC;14,3478;0,3109
1;LMC;14,0999;0,357
1;LMC;14,5558;0,2632
1;LMC;13,7602;0,4936
1;LMC;14,5354;0,2775
1;LMC;13,5663;0,5364
1;LMC;17,0694;-0,4754
1;LMC;14,2915;0,3346
1;LMC;14,7311;0,218
1;LMC;13,6888;0,5417
1;LMC;14,627;0,2133
1;LMC;13,4404;0,597
1;LMC;14,7168;0,2212
1;LMC;15,0594;0,3161
1;LMC;15,0425;0,1061
1;LMC;16,815;-0,4438
1;LMC;16,001;-0,1914
1;LMC;14,4216;0,2488
1;LMC;14,4748;0,286
1;LMC;13,8631;0,466
1;LMC;14,676;0,2098
1;LMC;14,4089;0,3046
1;LMC;14,2384;0,3559
1;LMC;14,2154;0,3397
1;LMC;14,059;0,3829
1;LMC;14,7006;0,2089
1;LMC;13,2151;0,6923
1;LMC;14,5228;0,2442
1;LMC;14,1972;0,3233
1;LMC;14,7161;0,2052
1;LMC;14,4328;0,2944
1;LMC;14,4018;0,2906
1;LMC;14,7142;0,2083
1;LMC;14,5522;0,2311
1;LMC;13,6784;0,5121
1;LMC;14,396;0,31
1;LMC;14,5408;0,2582
1;LMC;13,9204;0,4699
1;LMC;14,3842;0,308
1;LMC;13,9161;0,4451
1;LMC;14,5161;0,2751
1;LMC;16,6794;-0,4003
1;LMC;14,2213;0,3356
1;LMC;14,0804;0,3867
1;LMC;14,3438;0,2957
1;LMC;16,7434;-0,4476
1;LMC;14,4333;0,2808
1;LMC;14,3312;0,2889
1;LMC;14,504;0,247
1;LMC;13,2101;0,6412
1;LMC;13,8247;0,4442
1;LMC;13,962;0,4153
1;LMC;14,0806;0,3598
1;LMC;14,4793;0,2675
1;LMC;14,8813;0,1499
1;LMC;14,5757;0,2212
1;LMC;14,409;0,2996
1;LMC;13,8864;0,4335
1;LMC;14,1462;0,3252
1;LMC;13,4634;0,5562
1;LMC;14,034;0,4077
1;LMC;17,5882;-0,6029
1;LMC;13,7698;0,4653
1;LMC;14,3287;0,3083
1;LMC;13,2086;0,6234
1;LMC;13,5732;0,546
1;LMC;15,48;-0,014
1;LMC;13,1248;0,6751
1;LMC;17,1166;-0,528
1;LMC;13,9133;0,4573
1;LMC;15,0072;0,1038
1;LMC;14,1087;0,3766
1;LMC;17,1206;-0,5551
1;LMC;14,6866;0,2054
1;LMC;13,4114;0,5868
1;LMC;15,8548;-0,1511
1;LMC;12,2802;0,6877
1;LMC;17,1984;-0,5196
1;LMC;13,2713;0,6421
1;LMC;14,537;0,2466
1;LMC;15,4264;0,0006
1;LMC;15,5466;-0,0351
1;LMC;14,5549;0,3135
1;LMC;14,8506;0,1502
1;LMC;15,1214;0,0971
1;LMC;14,0284;0,3934
1;LMC;13,0608;0,6455
1;LMC;14,4624;0,2676
1;LMC;15,2442;0,0527
1;LMC;13,9045;0,4276
1;LMC;14,0536;0,3947
1;LMC;14,0503;0,3833
1;LMC;14,2145;0,3506
1;LMC;14,3653;0,2799
1;LMC;12,2534;0,6564
1;LMC;13,4538;0,5395
1;LMC;16,7458;-0,3898
1;LMC;13,799;0,4515
1;LMC;14,3382;0,2787
1;LMC;13,6368;0,5072
1;LMC;13,4912;0,5308
1;LMC;14,8163;0,1739
1;LMC;13,8256;0,4412
1;LMC;14,3908;0,2858
1;LMC;14,9267;0,0972
1;LMC;14,5064;0,2072
1;LMC;13,899;0,4303
1;LMC;14,0764;0,3825
1;LMC;14,871;0,1848
1;LMC;14,8902;0,1544
1;LMC;14,1546;0,3697
1;LMC;14,7806;0,1531
1;LMC;15,3816;0,0162
1;LMC;14,1212;0,3378
1;LMC;14,6768;0,1847
1;LMC;14,229;0,3145
1;LMC;14,3439;0,2859
1;LMC;14,5225;0,183
1;LMC;14,222;0,3029
1;LMC;14,6786;0,2644
1;LMC;14,2882;0,3067
1;LMC;17,304;-0,4965
1;LMC;13,2234;0,6359
1;LMC;14,1998;0,341
1;LMC;16,9782;-0,4488
1;SMC;14,2801;0,5215
1;SMC;16,7184;-0,1413
1;SMC;15,6902;0,0745
1;SMC;16,1686;-0,057
1;SMC;14,6436;0,3746
1;SMC;16,573;-0,1489
1;SMC;15,4925;0,1575
1;SMC;15,0159;0,3255
1;SMC;15,5657;0,1226
1;SMC;14,3219;0,4484
1;SMC;16,5712;-0,1446
1;SMC;16,1988;-0,0829
1;SMC;15,4376;0,1613
1;SMC;13,6344;0,5874
1;SMC;14,3778;0,4716
1;SMC;14,2394;0,5057
1;SMC;15,8777;0,0206
1;SMC;16,7138;-0,1735
1;SMC;15,7367;0,0683
1;SMC;14,7922;0,3067
1;SMC;17,9934;-0,5486
1;SMC;14,1358;0,5249
1;SMC;14,8562;0,3176
1;SMC;15,5588;0,1312
1;SMC;14,3;0,5272
1;SMC;15,6038;0,0537
1;SMC;14,5812;0,4347
1;SMC;14,8804;0,3115
1;SMC;14,3614;0,4934
1;SMC;16,4298;-0,0449
1;SMC;15,8712;0,0365
1;SMC;14,3527;0,5141
1;SMC;15,639;0,0993
1;SMC;14,0709;0,4997
1;SMC;16,0837;0,0029
1;SMC;14,7445;0,4165
1;SMC;16,23;-0,0246
1;SMC;15,1252;0,2608
1;SMC;16,255;-0,043
1;SMC;15,4152;0,2079
1;SMC;15,6954;0,0998
1;SMC;14,8665;0,3692
1;SMC;15,7832;0,0378
1;SMC;14,8404;-0,2293
1;SMC;15,9228;0,0104
1;SMC;16,1484;0,0015
1;SMC;15,8728;0,0054
1;SMC;14,8986;0,2908
1;SMC;16,731;-0,2169
1;SMC;15,2766;0,1077
1;SMC;15,5933;0,0706
1;SMC;14,6399;0,3879
1;SMC;16,4613;-0,0989
1;SMC;15,1788;0,1832
1;SMC;16,2002;-0,0848
1;SMC;15,0008;0,2784
1;SMC;14,7586;0,2794
1;SMC;16,3034;-0,118
1;SMC;16,4006;-0,1251
1;SMC;15,849;-0,0155
1;SMC;16,3728;-0,0437
1;SMC;13,959;0,5954
1;SMC;15,9233;0,0135
1;SMC;15,1752;0,2438
1;SMC;14,8222;0,3179
1;SMC;16,0276;0,0558
1;SMC;15,2084;0,1235
1;SMC;16,3546;-0,1292
1;SMC;14,5508;0,4422
1;SMC;15,656;0,1128
1;SMC;15,2515;0,2473
1;SMC;15,8121;0,0231
1;SMC;15,6758;0,0838
1;SMC;16,729;-0,1389
1;SMC;16,2468;-0,126
1;SMC;13,9121;0,5834
1;SMC;14,368;0,4634
1;SMC;15,7206;0,0583
1;SMC;15,6693;0,0931
1;SMC;16,2687;-0,0599
1;SMC;15,0676;0,227
1;SMC;15,5143;0,1668
1;SMC;15,7076;0,0811
1;SMC;15,566;0,0386
1;SMC;16,1032;-0,0477
1;SMC;16,2852;-0,0936
1;SMC;13,9415;0,5344
1;SMC;13,7318;0,6038
1;SMC;14,6932;0,2731
1;SMC;17,5597;-0,4531
1;SMC;15,6816;0,0183
1;SMC;16,6984;-0,0744
1;SMC;15,0062;0,2869
1;SMC;15,8423;0,0837
1;SMC;15,6786;0,1166
1;SMC;14,6876;0,3651
1;SMC;15,5642;0,1374
1;SMC;16,8114;-0,1078
1;SMC;14,795;0,2782
1;SMC;14,2601;0,4012
1;SMC;16,4018;-0,1529
1;SMC;14,9727;0,2929
1;SMC;15,5267;0,1388
1;SMC;15,0455;0,2939
1;SMC;16,1594;-0,0279
1;SMC;15,6552;0,0574
1;SMC;14,4008;0,4278
1;SMC;16,1806;-0,0993
1;SMC;15,8383;0,0532
1;SMC;15,4704;0,1488
1;SMC;16,3872;-0,0714
1;SMC;14,7915;0,3349
1;SMC;13,9011;0,5528
1;SMC;16,5788;-0,1133
1;SMC;13,9728;0,5471
1;SMC;15,8312;0,048
1;SMC;15,696;0,0947
1;SMC;16,378;-0,0909
1;SMC;15,3721;0,1404
1;SMC;14,9808;0,2511
1;SMC;15,7881;0,0277
1;SMC;15,7657;0,0796
1;SMC;15,9406;0,0803
1;SMC;15,5712;0,1499
1;SMC;15,4664;0,1231
1;SMC;16,3175;-0,0522
1;SMC;15,4929;0,1124
1;SMC;13,5586;0,3835
1;SMC;16,205;-0,0705
1;SMC;15,55;0,08
1;SMC;17,5096;-0,2768
1;SMC;15,8832;0,0417
1;SMC;17,738;-0,542
1;SMC;14,5475;0,4257
1;SMC;15,4079;0,0751
1;SMC;16,2626;0,0103
1;SMC;14,5742;0,3754
1;SMC;16,521;-0,1554
1;SMC;16,791;-0,1832
1;SMC;15,4673;0,1727
1;SMC;14,2996;0,4629
1;SMC;13,6418;0,6525
1;SMC;15,7457;0,0729
1;SMC;15,4886;0,1447
1;SMC;14,7568;0,3357
1;SMC;15,482;0,1373
1;SMC;16,1634;-0,0447
1;SMC;15,7054;0,1234
1;SMC;14,5147;0,4154
1;SMC;15,0815;0,2683
1;SMC;15,992;-0,0153
1;SMC;14,3333;0,4373
1;SMC;15,3798;0,1507
1;SMC;15,957;-0,0025
1;SMC;15,889;0,0482
1;SMC;16,3458;-0,0707
1;SMC;15,565;0,17
1;SMC;15,0304;0,273
1;SMC;14,0869;0,4998
1;SMC;14,986;0,2767
1;SMC;16,144;-0,0551
1;SMC;15,5166;0,1347
1;SMC;14,3772;0,4966
1;SMC;15,8712;0,0196
1;SMC;14,6147;0,3938
1;SMC;16,7266;-0,1534
1;SMC;15,6266;0,1039
1;SMC;14,3126;0,4288
1;SMC;15,9238;-0,016
1;SMC;16,1556;-0,0916
1;SMC;14,6832;0,3555
1;SMC;14,9996;0,3125
1;SMC;14,8072;0,313
1;SMC;17,2238;-0,2249
1;SMC;14,2168;0,4893
1;SMC;16,0782;-0,0494
1;SMC;15,9124;0,0302
1;SMC;14,6897;0,3772
1;SMC;14,8998;0,317
1;SMC;14,3068;0,4708
1;SMC;14,9732;0,2529
1;SMC;16,1034;-0,0252
1;SMC;15,2416;0,2186
1;SMC;15,9578;-0,0056
1;SMC;14,605;0,3675
1;SMC;15,3892;0,1909
1;SMC;14,1306;0,5392
1;SMC;14,2198;0,4472
1;SMC;15,9806;0,1076
1;SMC;17,3222;-0,3888
1;SMC;14,8756;0,3077
1;SMC;16,4862;-0,1431
1;SMC;15,453;0,1643
1;SMC;15,719;0,105
1;SMC;15,0462;0,2544
1;SMC;14,3558;0,4541
1;SMC;13,7118;0,6472
1;SMC;14,9858;0,3054
1;SMC;14,7582;0,3293
1;SMC;15,8872;0,0343
1;SMC;14,2318;0,4783
1;SMC;15,7902;0,1023
1;SMC;15,7548;0,0084
1;SMC;16,3536;-0,1291
1;SMC;15,7356;0,0787
1;SMC;15,0988;0,2505
1;SMC;15,007;0,1926
1;SMC;15,0572;0,2629
1;SMC;15,4202;0,1177
1;SMC;14,5873;0,4062
1;SMC;14,274;0,472
1;SMC;15,953;0,032
1;SMC;15,1688;0,1666
1;SMC;15,4486;0,1694
1;SMC;16,2714;-0,084
1;SMC;14,1066;0,444
1;SMC;14,1883;0,4876
1;SMC;14,6876;0,3783
1;SMC;16,2804;-0,0307
1;SMC;16,004;0,0296
1;SMC;15,5427;0,0665
1;SMC;15,2691;0,1932
1;SMC;15,0723;0,2626
1;SMC;16,4086;-0,135
1;SMC;16,1279;-0,0629
1;SMC;14,6822;0,3247
1;SMC;16,1232;-0,1099
1;SMC;14,3967;0,4784
1;SMC;16,1678;-0,019
1;SMC;14,3868;0,4022
1;SMC;14,738;0,3264
1;SMC;15,8982;0,0036
1;SMC;16,0884;-0,0763
1;SMC;14,7889;0,3277
1;SMC;15,5037;0,1452
1;SMC;14,9974;0,3175
1;SMC;16,1114;-0,0793
1;SMC;15,5855;0,0736
1;SMC;15,1194;0,2507
1;SMC;15,1229;0,2498
1;SMC;15,5506;0,0998
1;SMC;15,8262;0,0085
1;SMC;17,6762;-0,4719
1;SMC;15,512;0,1091
1;SMC;15,1242;0,2304
1;SMC;14,8618;0,2606
1;SMC;15,8314;-0,0355
1;SMC;13,9661;0,5273
1;SMC;15,7528;0,0473
1;SMC;15,4834;0,1461
1;SMC;16,1654;0,0084
1;SMC;17,02;-0,0819
1;SMC;15,7764;0,0479
1;SMC;15,1877;0,2523
1;SMC;15,2879;0,1914
1;SMC;16,2964;-0,0454
1;SMC;15,5908;0,1223
1;SMC;15,6662;0,0394
1;SMC;15,5124;0,1418
1;SMC;14,876;0,2962
1;SMC;16,015;-0,0057
1;SMC;14,6491;0,4071
1;SMC;16,5376;-0,1862
1;SMC;16,4474;-0,1131
1;SMC;16,0558;0,0361
1;SMC;16,6338;-0,2435
1;SMC;18,2798;-0,5471
1;SMC;15,7256;0,0648
1;SMC;16,963;-0,2991
1;SMC;15,5069;0,1115
1;SMC;15,0298;0,1803
1;SMC;16,3346;-0,1174
1;SMC;14,794;0,3238
1;SMC;14,271;0,4877
1;SMC;15,9154;0,0438
1;SMC;16,5047;-0,1339
1;SMC;16,65;-0,1978
1;SMC;14,8017;0,3421
1;SMC;15,397;0,1778
1;SMC;16,8134;-0,2104
1;SMC;14,3519;0,421
1;SMC;14,6731;0,3168
1;SMC;15,2232;0,2349
1;SMC;14,6852;0,3608
1;SMC;14,9719;0,1979
1;SMC;15,1469;0,2306
1;SMC;15,2132;0,1439
1;SMC;14,788;0,3559
1;SMC;15,638;0,131
1;SMC;15,1227;0,1846
1;SMC;15,7846;-0,0333
1;SMC;16,1864;-0,0533
1;SMC;16,4067;-0,0201
1;SMC;16,7493;-0,236
1;SMC;16,5681;-0,2147
1;SMC;15,6974;0,0783
1;SMC;16,1395;-0,074
1;SMC;14,7655;0,3273
1;SMC;14,5638;0,3947
1;SMC;16,6594;-0,1952
1;SMC;16,1283;-0,0393
1;SMC;15,9034;0,0257
1;SMC;15,8515;0,0495
1;SMC;15,0717;0,3022
1;SMC;15,3598;0,1681
1;SMC;14,4274;0,4869
1;SMC;16,2396;-0,0553
1;SMC;16,082;-0,0294
1;SMC;14,8533;0,2512
1;SMC;14,6503;0,3586
1;SMC;16,1;-0,0353
1;SMC;15,6848;0,1708
1;SMC;15,9834;0,0201
1;SMC;14,3646;0,4274
1;SMC;15,285;0,1942
1;SMC;15,1247;0,2598
1;SMC;15,7448;0,0919
1;SMC;15,6758;0,1366
1;SMC;15,0902;0,226
1;SMC;14,0126;0,5439
1;SMC;15,9319;-0,082
1;SMC;15,0558;0,2398
1;SMC;14,5532;0,4375
1;SMC;14,8176;0,3557
1;SMC;15,1869;0,2378
1;SMC;14,5042;0,3989
1;SMC;14,7118;0,2721
1;SMC;14,5803;0,3939
1;SMC;15,4836;0,1186
1;SMC;15,2548;0,2071
1;SMC;15,5388;0,1499
1;SMC;15,507;0,1285
1;SMC;13,958;0,5414
1;SMC;16,4458;-0,0405
1;SMC;15,6919;0,0892
1;SMC;14,4196;0,4557
1;SMC;15,7577;0,03
1;SMC;16,382;-0,1317
1;SMC;14,456;0,4701
1;SMC;15,5165;0,0565
1;SMC;16,198;-0,0138
1;SMC;16,1511;-0,0355
1;SMC;14,3661;0,4568
1;SMC;15,088;0,2109
1;SMC;14,3802;0,4206
1;SMC;14,7786;0,2707
1;SMC;15,2855;0,3013
1;SMC;15,3114;0,1119
1;SMC;15,43;0,1134
1;SMC;16,1082;-0,0503
1;SMC;16,2348;-0,022
1;SMC;15,9953;-0,0417
1;SMC;15,2678;0,1952
1;SMC;15,1298;0,2325
1;SMC;15,1712;0,2456
1;SMC;15,5435;0,1342
1;SMC;15,8772;0,0307

A simple solution:
arrays=df.groupby(['Mode','Cloud']).apply(lambda grp : residual_function(grp))
residuals_value=[]
[residuals_value.extend(elem.tolist()) for elem in arrays]
df["residuals"]=residuals_value

Related

How to convert independent output lists to a dataframe

Hope you are having a great weekend. My problem is as follows:
For my designed model i am getting the following predictions:
[0.3182012736797333, 0.6817986965179443, 0.5067878365516663, 0.49321213364601135, 0.4795221984386444, 0.520477831363678, 0.532780110836029, 0.46721988916397095, 0.3282901346683502, 0.6717098355293274]
[0.362120658159256, 0.6378793120384216, 0.5134761929512024, 0.4865237772464752, 0.46048662066459656, 0.539513349533081, 0.5342788100242615, 0.4657211899757385, 0.34932515025138855, 0.6506748199462891]
[0.3647380471229553, 0.6352618932723999, 0.5087167620658875, 0.49128326773643494, 0.4709164798259735, 0.5290834903717041, 0.5408024787902832, 0.4591975510120392, 0.37024226784706116, 0.6297577023506165]
[0.43765324354171753, 0.5623468160629272, 0.505147397518158, 0.49485257267951965, 0.45281311869621277, 0.5471869111061096, 0.5416161417961121, 0.45838382840156555, 0.3789178133010864, 0.6210821866989136]
[0.44772887229919434, 0.5522711277008057, 0.5119441151618958, 0.48805591464042664, 0.46322566270828247, 0.5367743372917175, 0.5402485132217407, 0.45975151658058167, 0.4145151972770691, 0.5854847431182861]
[0.35674020648002625, 0.6432597637176514, 0.48104971647262573, 0.5189502835273743, 0.4554695188999176, 0.54453045129776, 0.5409557223320007, 0.45904430747032166, 0.3258989453315735, 0.6741010546684265]
[0.3909384310245514, 0.609061598777771, 0.4915180504322052, 0.5084819793701172, 0.45033228397369385, 0.5496677160263062, 0.5267384052276611, 0.47326159477233887, 0.34493446350097656, 0.6550655364990234]
[0.32971733808517456, 0.6702827215194702, 0.5224012732505798, 0.47759872674942017, 0.4692566692829132, 0.5307433605194092, 0.5360044836997986, 0.4639955163002014, 0.41811054944992065, 0.5818894505500793]
[0.37096619606018066, 0.6290338039398193, 0.5165190100669861, 0.4834809899330139, 0.4739859998226166, 0.526013970375061, 0.5340168476104736, 0.46598318219184875, 0.3438771069049835, 0.6561229228973389]
[0.4189890921115875, 0.5810109376907349, 0.52749103307724, 0.47250890731811523, 0.44485437870025635, 0.5551456212997437, 0.5398098230361938, 0.46019014716148376, 0.3739124536514282, 0.6260875463485718]
[0.3979812562465668, 0.6020187139511108, 0.5050275325775146, 0.49497246742248535, 0.4653399884700775, 0.5346599817276001, 0.537341833114624, 0.4626581072807312, 0.33742010593414307, 0.6625799536705017]
[0.368088960647583, 0.631911039352417, 0.49925288558006287, 0.5007471442222595, 0.4547160863876343, 0.545283854007721, 0.5408452749252319, 0.45915472507476807, 0.4053747355937958, 0.5946252346038818]
As you can see they are independent lists. I want to convert these lists into a dataframe. Although they are independent, they are coming out of a for loop, so i cannot append them because they are not coming at once.
Use:
data = [[0.3182012736797333, 0.6817986965179443, 0.5067878365516663, 0.49321213364601135, 0.4795221984386444, 0.520477831363678, 0.532780110836029, 0.46721988916397095, 0.3282901346683502, 0.6717098355293274],
[0.362120658159256, 0.6378793120384216, 0.5134761929512024, 0.4865237772464752, 0.46048662066459656, 0.539513349533081, 0.5342788100242615, 0.4657211899757385, 0.34932515025138855, 0.6506748199462891],
[0.3647380471229553, 0.6352618932723999, 0.5087167620658875, 0.49128326773643494, 0.4709164798259735, 0.5290834903717041, 0.5408024787902832, 0.4591975510120392, 0.37024226784706116, 0.6297577023506165],
[0.43765324354171753, 0.5623468160629272, 0.505147397518158, 0.49485257267951965, 0.45281311869621277, 0.5471869111061096, 0.5416161417961121, 0.45838382840156555, 0.3789178133010864, 0.6210821866989136],
[0.44772887229919434, 0.5522711277008057, 0.5119441151618958, 0.48805591464042664, 0.46322566270828247, 0.5367743372917175, 0.5402485132217407, 0.45975151658058167, 0.4145151972770691, 0.5854847431182861],
[0.35674020648002625, 0.6432597637176514, 0.48104971647262573, 0.5189502835273743, 0.4554695188999176, 0.54453045129776, 0.5409557223320007, 0.45904430747032166, 0.3258989453315735, 0.6741010546684265],
[0.3909384310245514, 0.609061598777771, 0.4915180504322052, 0.5084819793701172, 0.45033228397369385, 0.5496677160263062, 0.5267384052276611, 0.47326159477233887, 0.34493446350097656, 0.6550655364990234],
[0.32971733808517456, 0.6702827215194702, 0.5224012732505798, 0.47759872674942017, 0.4692566692829132, 0.5307433605194092, 0.5360044836997986, 0.4639955163002014, 0.41811054944992065, 0.5818894505500793],
[0.37096619606018066, 0.6290338039398193, 0.5165190100669861, 0.4834809899330139, 0.4739859998226166, 0.526013970375061, 0.5340168476104736, 0.46598318219184875, 0.3438771069049835, 0.6561229228973389],
[0.4189890921115875, 0.5810109376907349, 0.52749103307724, 0.47250890731811523, 0.44485437870025635, 0.5551456212997437, 0.5398098230361938, 0.46019014716148376, 0.3739124536514282, 0.6260875463485718],
[0.3979812562465668, 0.6020187139511108, 0.5050275325775146, 0.49497246742248535, 0.4653399884700775, 0.5346599817276001, 0.537341833114624, 0.4626581072807312, 0.33742010593414307, 0.6625799536705017],
[0.368088960647583, 0.631911039352417, 0.49925288558006287, 0.5007471442222595, 0.4547160863876343, 0.545283854007721, 0.5408452749252319, 0.45915472507476807, 0.4053747355937958, 0.5946252346038818]]
# Create this before your for loop
df = pd.DataFrame(columns = range(10))
for pred_list in data:
#Add this within your for loop
df = df.append(pd.Series(pred_list), ignore_index=True)
output:

Python Matrix/Vector Operations

I have an array with shape = (2, 257) and want to use each column which are vectors of shape = (2,) to create an array with shape = (2, 2) for each column.
Previously I did this by selecting each column by iterating through my input array
import numpy as np
for counter in input
x = np.array([input[0][counter], input[1][counter]])
y = np.conj(x)
y = y.T
E = x[:, None] * y
corr_matr = np.where(self.iterator == 1, E, alpha * self.altes_E[counter] + (1 - alpha) * E)
self.altes_E[counter] = corr_matr
However this is very slow and I would like to vectorize this calculation so in the end I will have an array containing my E variables for each column of my input variable. I tried to do so but I get broadcasting errors I am not able to solve.. So it will be great if someone helped me out!
Self.iterator will be removed and replaced by the first element of the new array containing all E arrays
My goal now is to have an Array which has the shape (257, 2, 2) and contains 257 2x2 corr_matr matrices. The n-th corr_matr depends on the n-1-th
Self.altes_E is this matrix I am looking for but I cant create it with my vectorized approach. Maybe you guys have an idea how I can create it vectorized without a for-loop.
Test data:
input = array([[ 3.94351315e-02+0.00000000e+00j, -1.50913336e-02+6.03795651e-04j,\n 1.99272113e-04-8.07005910e-04j, -4.67793985e-04+8.33903992e-04j,\n -2.64236148e-03+2.77521785e-05j, -1.49792915e-03+7.36359583e-04j,\n 1.50533594e-03-6.15859179e-04j, -6.54810392e-05-5.01831397e-04j,\n -1.01095434e-03-1.70553920e-04j, 5.81738784e-04+7.12800200e-04j,\n -3.11310287e-04-9.01545559e-04j, -5.86002908e-05-9.55615603e-04j,\n 1.44156235e-04+1.09251279e-03j, -4.87454341e-04+8.03194960e-05j,\n 3.78562845e-04+1.29788540e-04j, -4.87558912e-04+6.55677040e-04j,\n -4.87274113e-04-8.31101470e-04j, 8.16597471e-04+3.81774926e-04j,\n 5.89999582e-04-7.40645680e-05j, -7.03418446e-05-4.16067625e-04j,\n -1.02284759e-03+2.56541860e-04j, -7.25162530e-05-2.12897828e-04j,\n 2.86242195e-04+2.15252463e-04j, -6.97098238e-04-5.35675945e-04j,\n 4.49257188e-04+4.96744002e-04j, 2.86015111e-04+9.92285825e-05j,\n -6.63212048e-05-1.97287145e-04j, -4.96012767e-05+1.68083300e-04j,\n -3.68913382e-04-1.76126405e-04j, 3.05618600e-04-2.13305860e-05j,\n -1.22923172e-04-3.58717400e-04j, -3.92479536e-04+1.02063591e-03j,\n 6.45622389e-04-8.53094144e-04j, -3.14203107e-04+1.47936574e-04j,\n 1.54020776e-05-2.45868608e-05j, 2.78312174e-04+2.11224838e-04j,\n -1.70668244e-04+4.57545662e-04j, 1.89143085e-04-1.62612861e-04j,\n -5.05276967e-04-7.33565277e-04j, 3.87931183e-04+6.84968797e-05j,\n -3.88693353e-04+3.29574348e-04j, 1.88775042e-05+3.06450544e-04j,\n -1.02881416e-04-6.28814378e-04j, 1.50437664e-04-4.64790639e-05j,\n 6.80136794e-05+7.07755678e-04j, 4.29081846e-04-6.60769121e-06j,\n -3.89883869e-05+9.94456323e-05j, -2.88405737e-04-3.90610565e-04j,\n 2.89706554e-04-4.61313935e-04j, 8.53534820e-05+3.45993148e-04j,\n -6.48341994e-04+1.61728688e-05j, 7.08075756e-04+4.18876357e-04j,\n -2.41676738e-04-6.57686042e-04j, -4.52960231e-05+4.69549856e-04j,\n -2.98667220e-04+3.69428944e-04j, 3.09898762e-04-5.55573884e-04j,\n 3.16198618e-05-2.18262971e-04j, -2.43962041e-05+6.14800458e-04j,\n 1.22281179e-04-4.27259031e-05j, -2.02764807e-04-3.04080095e-04j,\n -2.60131161e-05-2.72507038e-04j, -3.48411552e-04-1.65106382e-04j,\n 3.60262912e-04+1.15929180e-03j, 6.44188577e-04-6.57529271e-04j,\n -6.64472633e-04+7.34788284e-05j, -2.53962823e-04-8.64577990e-05j,\n 4.12548109e-04-4.30493761e-04j, -3.89652217e-04+1.10427049e-03j,\n 2.19613546e-04-6.47350601e-04j, -3.01855256e-04-1.70512519e-04j,\n 3.52232474e-04-5.97253780e-04j, -2.46726574e-04+8.25901553e-05j,\n 5.01323354e-04+4.97268616e-04j, -3.87112186e-04+2.31773757e-04j,\n -5.51833095e-04+5.28582216e-04j, 1.52037945e-04-9.87780746e-04j,\n 1.80951699e-04-1.64293165e-04j, 9.81853960e-04+8.24736454e-04j,\n -3.08003998e-04+4.10959821e-05j, -7.18984896e-04+9.56216393e-05j,\n 9.23759625e-06-5.16799160e-04j, 3.62720586e-04-4.27438243e-04j,\n 4.54825689e-04+6.60654467e-04j, -8.45689094e-04+3.84855215e-04j,\n -2.67177134e-05-7.42870583e-04j, -1.92531972e-04-3.02859614e-04j,\n 7.90923909e-04+2.13245532e-04j, -7.46436347e-04+4.59160357e-04j,\n 2.42516064e-04+5.79452623e-04j, 2.76445921e-04-1.07193028e-03j,\n -5.72620393e-04+1.96574790e-04j, 1.34058726e-03+2.34585361e-04j,\n -3.57420647e-04-1.70451007e-04j, -2.82518121e-04+2.07459060e-04j,\n -4.28715245e-05-3.11639838e-04j, -2.31994207e-04-3.50393413e-04j,\n 1.79812526e-04+9.46405559e-06j, 6.45826858e-06-7.27244722e-05j,\n -6.54773349e-04+9.59387600e-04j, 3.84335152e-04-2.72657471e-04j,\n -4.87276832e-04-3.96541032e-04j, 6.77017368e-04+4.47778225e-04j,\n 4.45890499e-04+1.29559357e-04j, -6.51094304e-04+1.86624435e-04j,\n 3.98953747e-05-4.33256129e-04j, -2.22111375e-04-2.04651458e-04j,\n 7.55794351e-04-5.85769035e-04j, -3.94789819e-04+1.04401607e-03j,\n -1.58222133e-04+1.11208833e-05j, 9.23486664e-05-7.75775861e-04j,\n -3.43146772e-04+1.17239880e-04j, 2.84564728e-04+6.11844429e-06j,\n 4.70805410e-04+3.47810038e-04j, 1.69658330e-04-6.84370728e-06j,\n -5.22356227e-04+6.50334373e-04j, -1.73679813e-04+3.63334974e-05j,\n 4.98834691e-04-1.01761885e-03j, 5.87157344e-04+1.20334407e-04j,\n -9.03141283e-04+5.43231194e-04j, 2.12604011e-04+4.25936737e-05j,\n 1.20421975e-04+1.99248114e-04j, 1.36291525e-04-1.74378105e-04j,\n -3.22569755e-04-3.90555480e-04j, -8.56585373e-04-1.36390458e-05j,\n 8.21771053e-04+5.11195915e-04j, -1.32706058e-04-6.24514006e-05j,\n -5.38444724e-04-7.24478095e-04j, 1.28496700e-03+2.93993678e-05j,\n -6.10961533e-04+1.10329922e-04j, -3.67753624e-04+2.46454903e-04j,\n -1.97998194e-04+4.12632455e-04j, 4.80604477e-04-2.31270841e-04j,\n 1.92777568e-05-4.07627748e-04j, 2.86666234e-04+7.01966268e-05j,\n 1.15379387e-04-1.33773849e-04j, -3.17265283e-04+5.00725722e-04j,\n 1.36599939e-04-6.75427006e-04j, 6.37731351e-05+7.04635115e-04j,\n -1.96653870e-04+3.25483834e-04j, -5.86921673e-04-1.23419379e-03j,\n 3.14143574e-04+1.00360594e-04j, 3.31560079e-04+1.07206559e-03j,\n 4.92924636e-05-5.68876368e-04j, -8.41042140e-04+3.22939688e-04j,\n 5.49575067e-04-5.15098419e-05j, -3.93180240e-04-4.42074142e-05j,\n 5.60555298e-04-2.85327349e-04j, -2.38831244e-04+1.91581065e-05j,\n -7.45519046e-05+1.27549869e-04j, -5.89318659e-05-4.21902661e-04j,\n 3.75275146e-04+1.82785513e-05j, -2.34356665e-04+4.60409956e-04j,\n -1.92879655e-04+2.25686712e-05j, 2.29916609e-04-3.98052727e-04j,\n 1.14636467e-04+3.40506254e-04j, 3.66346397e-04+4.71324904e-05j,\n -3.50054041e-04-5.13589144e-04j, -2.54987713e-04+1.99572441e-04j,\n 5.45736142e-07-5.96936864e-05j, -1.24422570e-04+9.28100584e-05j,\n -3.07471848e-04-4.81938971e-05j, 8.54350904e-04+8.01221802e-05j,\n -1.36143168e-03+1.05957395e-04j, 4.67515499e-04+1.18207109e-04j,\n 2.22224539e-04-7.87005141e-04j, 2.06836573e-04+7.33415318e-04j,\n 4.11857186e-05-2.78641304e-04j, 8.46935368e-05+2.47412699e-05j,\n 9.63134514e-05-6.25919599e-04j, -1.74852058e-04+6.83190116e-04j,\n 5.17474224e-05-2.10492739e-05j, 5.02637722e-05+8.55532060e-06j,\n -1.48067521e-04+1.27482971e-04j, -3.17709988e-04-3.19972013e-04j,\n 7.93806547e-04+7.24172271e-04j, 3.71753847e-04-2.96357705e-04j,\n -7.16045744e-04-2.45445209e-04j, 1.85488700e-04-7.80975779e-05j,\n -6.33931296e-04-3.79990485e-04j, 4.23058885e-04+5.71413970e-04j,\n -1.96111954e-04-1.64805179e-04j, -2.39387453e-04+4.67926668e-04j,\n 4.48049475e-04-4.39783397e-04j, -4.57884754e-04-8.64764107e-05j,\n 2.36198689e-04-1.81618919e-04j, -3.98041496e-04+5.49284505e-04j,\n 7.71543104e-04+2.33418707e-04j, -5.37125816e-04-1.39968077e-04j,\n 1.21667266e-04+2.94272358e-05j, -4.22621149e-05-4.03145881e-04j,\n 5.15855772e-04+6.12452186e-05j, -1.75597310e-04+3.06332086e-04j,\n 9.80239412e-05-5.22006358e-04j, -3.91105404e-04+7.24365490e-04j,\n 5.41880105e-04-6.62486843e-04j, -1.44683949e-04+2.83522226e-04j,\n -1.91702886e-04+1.31554681e-04j, 5.24558737e-05-1.08982522e-04j,\n 6.74327223e-04+1.10659354e-04j, -5.79971252e-04+1.77968960e-04j,\n -2.51067236e-04-1.07853197e-04j, 3.11939498e-04-1.38577070e-04j,\n -6.04476470e-05+8.52540539e-05j, 1.34265204e-04+8.21556997e-04j,\n -1.17370999e-04-7.91857871e-04j, 2.79181388e-04-7.31803351e-04j,\n -6.90453886e-04+7.46784829e-04j, -1.16164963e-04-4.57167257e-04j,\n -4.69417951e-04-4.41735735e-04j, 1.35998487e-05+1.12007021e-03j,\n 3.29877562e-04+1.48284571e-04j, 5.83769268e-04+2.49004599e-04j,\n -7.52982150e-04-1.68075249e-03j, -3.38846404e-04+9.63951937e-04j,\n 3.55617024e-04-1.27152987e-04j, 8.13345170e-04-4.35530692e-04j,\n 2.21017421e-04+3.81957629e-04j, -2.29169840e-04+4.31749297e-04j,\n -3.49092860e-04-5.49892781e-04j, 1.47060146e-05-4.94382810e-04j,\n 8.50208905e-04+7.47663086e-05j, -1.45781683e-04+3.05060633e-04j,\n -5.68202031e-04+2.25181950e-04j, -6.70225923e-05-4.04705073e-04j,\n 5.49901664e-04+1.00974501e-03j, 1.09107837e-05-4.09919474e-04j,\n -7.08992001e-04-6.93567150e-04j, 2.38546368e-05+3.33138967e-04j,\n 6.59087722e-04+4.15920176e-04j, -9.24723091e-04+5.72433162e-04j,\n 3.16802067e-04-1.97599886e-04j, 9.59921563e-04-7.20312263e-04j,\n -2.04590275e-04-7.58383004e-04j, -9.83521376e-04+1.39303955e-03j,\n 1.00191560e-03-1.06808718e-03j, -1.44975474e-04+2.10013067e-04j,\n 1.57355072e-04-8.06148227e-05j, -9.77899528e-04+1.01124440e-03j,\n 1.40629188e-04+3.07843307e-04j, 4.58437822e-04-1.54270986e-03j,\n -3.58655124e-06+3.05346109e-04j, -8.51095471e-04+9.50186675e-04j,\n 6.49841806e-04-3.69990669e-04j, -2.42669267e-04+1.97887318e-04j,\n 1.08560919e-03-5.57172096e-04j, -1.38075404e-03+3.06128065e-04j,\n -2.99248592e-04-1.96865567e-04j, 4.34882427e-04+6.50054051e-05j,\n 1.09891678e-03+1.84768495e-04j, -7.36401037e-04-1.54611504e-03j,\n 1.95455637e-04+1.59373547e-03j, -1.65580093e-04-1.90926799e-04j,\n -1.13688576e-04+4.12506434e-04j, 1.12544155e-03+4.77414267e-04j,\n -1.31365139e-03-1.41451042e-03j, 5.79908017e-04+1.48045447e-04j,\n -4.82300426e-04+0.00000000e+00j],\n [ 3.94302788e-02+0.00000000e+00j, -1.50769610e-02+6.62688618e-04j,\n 1.63792293e-04-9.09965691e-04j, -4.20457549e-04+7.67888474e-04j,\n -2.62611773e-03+1.79287284e-04j, -1.39992458e-03+8.62646142e-04j,\n 1.43622367e-03-8.15390156e-04j, -1.32725278e-04-5.22439730e-04j,\n -1.02788776e-03-2.84542025e-05j, 7.04202642e-04+5.75840478e-04j,\n -4.85970329e-04-8.42626503e-04j, -2.85902831e-04-9.33336830e-04j,\n 3.85726455e-04+1.01063584e-03j, -4.54619102e-04+1.89852072e-04j,\n 3.96938522e-04+4.87940712e-06j, -2.64396836e-04+7.56253750e-04j,\n -7.20372356e-04-6.38146395e-04j, 8.97949930e-04+7.69071706e-05j,\n 5.23039447e-04-3.00850918e-04j, -2.30101044e-04-3.83685318e-04j,\n -8.45559655e-04+6.25181058e-04j, -1.55582013e-04-1.67400948e-04j,\n 3.48307983e-04+6.57074044e-05j, -8.67179548e-04-1.65800957e-04j,\n 6.26144481e-04+2.31985901e-04j, 2.96950721e-04-5.87318674e-05j,\n -1.59847453e-04-1.45575757e-04j, 4.17422830e-05+1.62311722e-04j,\n -4.06935839e-04+4.60837714e-05j, 2.40112226e-04-1.88702128e-04j,\n -3.12380034e-04-2.25416888e-04j, 2.83110337e-04+1.05608322e-03j,\n 1.69140411e-06-1.07341915e-03j, -1.61321781e-04+3.08879494e-04j,\n -7.12735790e-06-2.89430707e-05j, 3.44852190e-04-2.42375302e-05j,\n 1.77649387e-04+4.46179235e-04j, 3.00653183e-05-2.58839835e-04j,\n -8.75480076e-04-1.78086957e-04j, 3.15614668e-04-2.23862597e-04j,\n -3.28856251e-05+5.09215677e-04j, 2.42580737e-04+1.91265064e-04j,\n -5.38095552e-04-3.36387834e-04j, 5.89000296e-05-1.38800403e-04j,\n 5.93041602e-04+3.91920304e-04j, 2.58312359e-04-3.52047888e-04j,\n 5.41664911e-05+7.84828629e-05j, -4.87040484e-04+2.00465143e-07j,\n -2.24098958e-04-5.00037983e-04j, 3.25842394e-04+1.16315659e-04j,\n -3.33712131e-04+5.56801846e-04j, 7.20763407e-04-3.98413351e-04j,\n -6.98367513e-04-1.21573550e-04j, 3.84986333e-04+2.61687346e-04j,\n 1.91783081e-04+4.26843301e-04j, -3.61446144e-04-5.30072060e-04j,\n -1.90875135e-04-1.22069126e-04j, 5.47142772e-04+2.66855906e-04j,\n 4.08724905e-06-1.39431456e-04j, -3.61842034e-04+7.01928105e-05j,\n -2.68947677e-04-7.08310314e-05j, -2.73181365e-04+2.79827782e-04j,\n 1.21452700e-03+1.36751774e-05j, -4.48800651e-04-8.19776275e-04j,\n -1.19266297e-04+6.53314340e-04j, -1.48156234e-04+2.20506208e-04j,\n -3.25802814e-04-5.00083015e-04j, 9.93835264e-04+6.10726403e-04j,\n -5.92139594e-04-3.50046309e-04j, -2.20551315e-04+2.66541088e-04j,\n -5.38101746e-04-4.33232244e-04j, 4.53140432e-05+2.67048105e-04j,\n 5.45584100e-04-4.36233554e-04j, 1.89055956e-04+4.05146241e-04j,\n 4.91230583e-04+5.80214622e-04j, -9.70303336e-04-2.07957665e-04j,\n -1.54105042e-04-1.78764985e-04j, 8.29454691e-04-9.70980630e-04j,\n 2.93041276e-05+2.99636023e-04j, 1.11761881e-04+7.06579832e-04j,\n -5.13429489e-04+1.03407490e-05j, -4.51280720e-04-3.28230045e-04j,\n 6.09306297e-04-5.08877271e-04j, 4.69052361e-04+7.90693011e-04j,\n -7.29652303e-04+1.16791352e-04j, -2.63583592e-04+2.40084959e-04j,\n 7.80339281e-05-8.09166755e-04j, 5.91733367e-04+6.46003586e-04j,\n 5.18742468e-04-3.69670376e-04j, -1.10819540e-03-2.98322967e-05j,\n 3.35961109e-04+5.08219023e-04j, -1.37905601e-04-1.35428372e-03j,\n -7.54841905e-05+3.93744885e-04j, 2.75316936e-04+2.05765280e-04j,\n -2.85925096e-04+1.42533512e-04j, -2.49244553e-04+3.44507517e-04j,\n -5.49966896e-05-1.61934566e-04j, -6.94024634e-05+3.21277311e-05j,\n 1.14427279e-03+2.14503629e-04j, -4.06256577e-04-2.42573698e-04j,\n -1.37008788e-04+6.09181906e-04j, 9.41131852e-05-8.08853747e-04j,\n -1.05763981e-04-4.56058417e-04j, 4.74122378e-04+4.69608012e-04j,\n -3.95122830e-04+1.79715038e-04j, -5.41657307e-05+2.94641051e-04j,\n -8.99698699e-04-3.08409334e-04j, 1.08313369e-03-2.52154929e-04j,\n 9.61555026e-05+1.16751009e-04j, -6.78396810e-04+3.85853518e-04j,\n 3.08973305e-04+2.04145634e-04j, -1.66564595e-04-2.23731139e-04j,\n -3.64032556e-05-5.80136045e-04j, -1.25077116e-04-1.17649763e-04j,\n 8.22473217e-04-5.10403627e-05j, 1.35846968e-04+9.04349589e-05j,\n -1.08069909e-03+3.56424784e-04j, -3.42539982e-04-4.83310914e-04j,\n 1.02127798e-03+2.27836680e-04j, -1.38094505e-04-1.76668123e-04j,\n 2.64921676e-05-2.31094625e-04j, -2.30827528e-04+4.76342119e-05j,\n 1.46863589e-07+5.09299510e-04j, 6.74095347e-04+5.26744232e-04j,\n -3.63377125e-04-9.05099052e-04j, 6.26177364e-05+1.23244300e-04j,\n 4.31863072e-05+8.96514097e-04j, -1.06310512e-03-7.14346108e-04j,\n 5.75517243e-04+2.35967322e-04j, 4.41244980e-04-2.65860383e-05j,\n 3.70694639e-04-2.71684200e-04j, -5.39649217e-04-2.89578543e-05j,\n -2.05237670e-04+3.55566693e-04j, -2.29304581e-04-1.82601791e-04j,\n -1.63278707e-04+8.28089685e-05j, 4.85237610e-04-3.27131430e-04j,\n -3.85198889e-04+5.78130634e-04j, 1.91039368e-04-6.73331290e-04j,\n 2.83290401e-04-2.36600115e-04j, 1.56155251e-04+1.35530242e-03j,\n -2.58546407e-04-1.92172329e-04j, -1.64289988e-05-1.12061403e-03j,\n -2.06761243e-04+5.39404115e-04j, 8.90146217e-04-1.10273389e-04j,\n -5.53419489e-04-8.01172163e-05j, 3.69800922e-04+1.19385537e-04j,\n -6.06753749e-04+1.74073233e-04j, 2.37762330e-04+2.21509768e-05j,\n 9.04367392e-05-1.17178154e-04j, 6.65735029e-06+4.23161474e-04j,\n -3.66355661e-04-5.69644277e-05j, 2.72752455e-04-4.36970254e-04j,\n 1.89332418e-04-1.28477791e-05j, -2.48450704e-04+3.85021186e-04j,\n -1.06569421e-04-3.41965661e-04j, -3.70428389e-04-4.26724302e-05j,\n 3.58595638e-04+5.14301117e-04j, 2.51269109e-04-2.08539926e-04j,\n 4.88939967e-06+5.71210855e-05j, 1.18578623e-04-1.05802288e-04j,\n 3.11344492e-04+1.01891390e-05j, -8.56978432e-04+1.74893270e-05j,\n 1.33232876e-03-2.98487141e-04j, -4.85805120e-04-5.94291833e-05j,\n -7.76562206e-05+8.03680105e-04j, -3.43743448e-04-6.84465578e-04j,\n 1.92205105e-05+2.78271830e-04j, -8.62407096e-05-6.06097609e-06j,\n 7.51468262e-05+6.27872523e-04j, -1.25139166e-05-7.07494831e-04j,\n -4.26531031e-05+3.33935842e-05j, -4.93983638e-05+6.62065104e-06j,\n 9.65211897e-05-1.71035129e-04j, 4.09508943e-04+1.81017834e-04j,\n -1.00836515e-03-3.78649449e-04j, -2.28902765e-04+4.29769144e-04j,\n 7.55644169e-04-6.15984149e-05j, -1.31806876e-04+1.50093610e-04j,\n 7.41534101e-04+5.25070731e-05j, -6.37489984e-04-3.17623167e-04j,\n 2.50510928e-04+4.72741634e-05j, -3.12101871e-05-5.30198666e-04j,\n -1.61833058e-04+6.04663509e-04j, 4.33069517e-04-1.76875910e-04j,\n -9.68597935e-05+2.72233313e-04j, 1.29069366e-05-6.86698274e-04j,\n -7.70844850e-04+2.59679250e-04j, 5.06334114e-04-2.08281614e-04j,\n -1.23040807e-04+4.96912636e-05j, 2.81721303e-04+2.82239777e-04j,\n -4.32856798e-04+2.85045100e-04j, -7.18904719e-05-3.42817657e-04j,\n 2.82159126e-04+4.51272457e-04j, -2.22012038e-04-7.93265681e-04j,\n 8.25420573e-05+8.53400594e-04j, -1.00706437e-04-2.98939601e-04j,\n 3.14683041e-05-2.27519261e-04j, 4.36941077e-05+1.13381143e-04j,\n -5.18682202e-04+4.48501226e-04j, 2.30610517e-04-5.52246756e-04j,\n 2.34490912e-04-1.26264973e-04j, -7.97095177e-05+3.35952614e-04j,\n -3.45318332e-05-9.44128409e-05j, -7.57633937e-04-3.43506355e-04j,\n 7.20500401e-04+3.51295162e-04j, 4.74556384e-04+6.27668922e-04j,\n -2.81101536e-04-9.78262731e-04j, 4.46874372e-04+1.24837907e-04j,\n 6.05163789e-04-2.12023275e-04j, -1.01407397e-03-5.16929477e-04j,\n -2.98164906e-04+2.33126469e-04j, -4.86355494e-04+4.33123201e-04j,\n 1.83462356e-03-7.71867376e-07j, -7.69209261e-04-7.01104884e-04j,\n -3.18641790e-05+3.73050143e-04j, 1.15613125e-04+9.09600948e-04j,\n -4.28446346e-04+7.86494004e-05j, -3.34852105e-04-3.47817544e-04j,\n 6.26099520e-04-1.68044497e-04j, 4.68369045e-04+1.42514209e-04j,\n -2.83908873e-04+7.92399750e-04j, -2.49184244e-04-2.18710226e-04j,\n -9.19001071e-05-6.04839544e-04j, 4.08264053e-04+9.93217421e-06j,\n -1.08943196e-03+3.64046481e-04j, 4.09723216e-04+8.49350013e-05j,\n 7.86130478e-04-6.09249721e-04j, -3.38645074e-04-2.27244838e-05j,\n -4.77324227e-04+6.16456017e-04j, -5.01373021e-04-9.55310274e-04j,\n 1.70573740e-04+3.42094097e-04j, 6.89184712e-04+9.91871858e-04j,\n 7.74817539e-04-2.00708515e-04j, -1.39524815e-03-9.81590142e-04j,\n 1.09255944e-03+9.77000557e-04j, -2.06580095e-04-1.44088734e-04j,\n 1.00169291e-04+1.44579525e-04j, -1.08783213e-03-8.86595885e-04j,\n -2.96315620e-04+1.88823864e-04j, 1.58771473e-03+2.66780661e-04j,\n -2.99713732e-04+3.14700680e-05j, -1.08078974e-03-6.78289646e-04j,\n 4.79116024e-04+5.81652824e-04j, -2.43603471e-04-1.88258714e-04j,\n 7.93634703e-04+9.36679925e-04j, -6.29229943e-04-1.26267628e-03j,\n 9.93210429e-05-3.33132766e-04j, 5.00382390e-05+4.41575210e-04j,\n 1.61111886e-04+1.10747772e-03j, 1.23195666e-03-1.20419700e-03j,\n -1.43246313e-03+7.18458426e-04j, 1.23366572e-04-2.18045537e-04j,\n -4.21981246e-04+5.80438962e-05j, 2.37621151e-05+1.23103317e-03j,\n 7.49466857e-04-1.79312642e-03j, 1.24531095e-04+4.69038221e-04j,\n -8.82536309e-04+0.00000000e+00j]])
self.altes_E = np.zeros((257, 2, 2), dtype = complex)
alpha = 0.8

Cumprod giving -inf in Python

I am trying to compute cumulative product of the following data set.
Date Random data
1/2/2006 2.372388507
1/3/2006 2.792095479
1/4/2006 4.153345633
1/5/2006 1.209302413
1/6/2006 3.308908843
1/9/2006 5.609288688
1/10/2006 5.148763856
1/11/2006 4.963421605
1/12/2006 4.031740124
1/13/2006 5.475643588
1/16/2006 5.310478512
1/17/2006 5.231183268
1/18/2006 7.33295124
1/19/2006 7.086467341
1/20/2006 6.953441702
1/23/2006 6.881551417
1/24/2006 6.720592121
1/25/2006 4.375483647
1/26/2006 2.824165469
1/27/2006 2.830542833
1/30/2006 3.735049499
1/31/2006 3.147491688
2/1/2006 1.414748374
2/2/2006 -0.051161849
2/3/2006 -0.180186506
2/6/2006 1.660894524
2/7/2006 2.709409323
2/8/2006 1.972035231
2/9/2006 -0.782625682
2/10/2006 -1.901299484
2/13/2006 -2.141229007
2/14/2006 -2.639233019
2/15/2006 -4.95219641
2/16/2006 -6.568204721
2/17/2006 -5.671892621
2/20/2006 -5.989308797
2/21/2006 -5.519832515
2/22/2006 -4.123507939
2/23/2006 -4.840716254
2/24/2006 -3.393895281
2/27/2006 -1.579450628
2/28/2006 -5.715894843
3/1/2006 -4.818584424
3/2/2006 -5.306398625
3/3/2006 -3.773552658
3/6/2006 -1.782726837
3/7/2006 -2.421770003
3/8/2006 -2.032466154
3/9/2006 -3.24379646
3/10/2006 0.267982805
3/13/2006 0.014589559
3/14/2006 1.343058431
3/15/2006 1.539251495
3/16/2006 -0.350651804
3/17/2006 -0.215041321
3/20/2006 0.578951429
3/21/2006 -0.576824159
3/22/2006 1.881264415
3/23/2006 2.714386498
3/24/2006 4.111298817
3/27/2006 5.020309083
3/28/2006 4.532650354
3/29/2006 7.245341261
3/30/2006 8.111802803
3/31/2006 4.558323469
4/3/2006 6.252751308
4/4/2006 8.314806951
4/5/2006 5.777692349
4/6/2006 6.725161553
4/7/2006 4.794367906
4/10/2006 5.743532122
4/11/2006 7.290548166
4/12/2006 5.903857018
4/13/2006 4.77936565
4/14/2006 5.674446806
4/17/2006 5.88485792
4/18/2006 6.078651917
4/19/2006 4.917405394
4/20/2006 4.868584712
4/21/2006 3.526253732
4/24/2006 5.124797759
4/25/2006 3.884862865
4/26/2006 4.369885748
4/27/2006 1.234703037
4/28/2006 -1.67674986
5/1/2006 -2.711339347
5/2/2006 -2.574835748
5/3/2006 -3.532974512
5/4/2006 -4.361912086
5/5/2006 -9.136912315
5/8/2006 -8.945826752
5/9/2006 -7.804639384
5/10/2006 -10.05905437
5/11/2006 -9.254733416
5/12/2006 -8.382467816
5/15/2006 -7.718500019
5/16/2006 -10.04179082
5/17/2006 -10.90960283
5/18/2006 -7.538484374
5/19/2006 -6.915045472
5/22/2006 -8.49018374
5/23/2006 -10.84341146
5/24/2006 -4.739280009
5/25/2006 -8.906757979
5/26/2006 -10.61262457
5/29/2006 -9.636827323
5/30/2006 -8.353511534
5/31/2006 -10.1389515
6/1/2006 -10.0339179
6/2/2006 -10.84551313
6/5/2006 -8.628081538
6/6/2006 -6.657905529
6/7/2006 -6.395791873
6/8/2006 -7.676135515
6/9/2006 -7.225332776
6/12/2006 -5.721847599
6/13/2006 -9.168934478
6/14/2006 -8.522434172
6/15/2006 -9.344608517
6/16/2006 -9.492790802
6/19/2006 -6.27304367
6/20/2006 -7.748707965
6/21/2006 -5.216536389
6/22/2006 -5.866333313
6/23/2006 -3.421767661
6/26/2006 -0.817150639
6/27/2006 1.566919066
6/28/2006 2.1756715
6/29/2006 2.003892417
6/30/2006 0.145706902
7/3/2006 4.825841191
7/4/2006 2.984194983
7/5/2006 2.733606852
7/6/2006 3.990344988
7/7/2006 4.464159978
7/10/2006 2.181922905
7/11/2006 4.207532649
7/12/2006 5.893857763
7/13/2006 6.696591003
7/14/2006 8.02397588
7/17/2006 7.18005379
7/18/2006 7.110823813
7/19/2006 4.604122492
7/20/2006 4.383075987
7/21/2006 4.734463235
7/24/2006 5.60625391
7/25/2006 7.453657745
7/26/2006 6.7147771
7/27/2006 5.255477178
7/28/2006 6.638942489
7/31/2006 5.514850947
8/1/2006 6.666282084
8/2/2006 6.037577365
8/3/2006 6.434382521
8/4/2006 5.80948075
8/7/2006 5.667054317
8/8/2006 5.175715003
8/9/2006 4.94937506
8/10/2006 3.558925269
8/11/2006 4.031802401
8/14/2006 3.272287286
8/15/2006 4.289470879
8/16/2006 3.538103725
8/17/2006 2.762386707
8/18/2006 2.114880041
8/21/2006 5.068950919
8/22/2006 2.483874694
8/23/2006 1.730699516
8/24/2006 -0.675212673
8/25/2006 0.187110629
8/28/2006 0.344282156
8/29/2006 0.01723009
8/30/2006 -0.327127005
8/31/2006 0.016483468
9/1/2006 -0.973496098
9/4/2006 -1.218588549
9/5/2006 -0.20940671
9/6/2006 0.25023559
9/7/2006 -2.986442703
9/8/2006 -2.073033591
9/11/2006 1.390003709
9/12/2006 2.940760338
9/13/2006 2.403386183
9/14/2006 2.349487863
9/15/2006 1.899995646
9/18/2006 3.50536463
9/19/2006 2.83392064
9/20/2006 2.571588424
9/21/2006 3.118297653
9/22/2006 -0.377687298
9/25/2006 -2.391993686
9/26/2006 0.712594429
9/27/2006 1.457682028
9/28/2006 1.474114727
9/29/2006 0.446453108
10/2/2006 3.007973689
10/3/2006 -2.43263121
10/4/2006 0.86295345
10/5/2006 4.664733649
10/6/2006 4.558573046
10/9/2006 4.680665577
10/10/2006 4.575158956
10/11/2006 6.425144162
10/12/2006 8.372432637
10/13/2006 8.182474544
10/16/2006 8.968786366
10/17/2006 9.463661551
10/18/2006 8.512907068
10/19/2006 5.873743873
10/20/2006 3.369445264
10/23/2006 1.030307363
10/24/2006 5.528218034
10/25/2006 4.772900213
10/26/2006 4.780839053
10/27/2006 4.908377081
10/30/2006 1.949064709
10/31/2006 1.237048868
11/1/2006 -0.784592691
11/2/2006 2.737788889
11/3/2006 0.575772221
11/6/2006 0.756429404
11/7/2006 3.470072539
11/8/2006 3.162250037
11/9/2006 3.530282875
11/10/2006 3.101909259
11/13/2006 3.850635629
11/14/2006 5.765932269
11/15/2006 6.872396495
11/16/2006 7.65256188
11/17/2006 7.665129818
11/20/2006 7.688611466
11/21/2006 10.98556762
11/22/2006 10.3474519
11/23/2006 8.307676877
11/24/2006 6.809710616
11/27/2006 3.833060531
11/28/2006 2.194899225
11/29/2006 2.753858429
11/30/2006 7.843689893
12/1/2006 7.960285607
12/4/2006 8.693168009
12/5/2006 6.942631629
12/6/2006 7.571515106
12/7/2006 9.703434772
12/8/2006 9.330900226
12/11/2006 10.07080936
12/12/2006 8.823865383
12/13/2006 9.142372346
12/14/2006 11.4249828
12/15/2006 13.4976679
12/18/2006 16.02891813
12/19/2006 13.57689804
12/20/2006 13.08135113
12/21/2006 11.35585478
12/22/2006 11.56407075
12/25/2006 12.55729202
12/26/2006 12.74006864
12/27/2006 12.80879851
12/28/2006 12.78104782
12/29/2006 10.84853655
1/1/2007 12.34247778
1/2/2007 12.4083186
1/3/2007 12.05157619
1/4/2007 13.31470937
1/5/2007 13.08023063
1/8/2007 11.8083914
1/9/2007 12.14102299
1/10/2007 12.78561441
1/11/2007 10.5599935
1/12/2007 9.670640578
1/15/2007 7.5265463
1/16/2007 5.785317873
1/17/2007 6.421764885
1/18/2007 6.13308998
1/19/2007 4.502378909
1/22/2007 5.18285115
1/23/2007 6.651267567
1/24/2007 9.669499091
1/25/2007 9.873389316
1/26/2007 8.512393515
1/29/2007 8.17935067
1/30/2007 7.565247724
1/31/2007 10.26027855
2/1/2007 12.21138996
2/2/2007 11.0873071
2/5/2007 15.28502878
2/6/2007 13.68842955
2/7/2007 13.27807961
2/8/2007 12.83276901
2/9/2007 13.80840316
2/12/2007 10.40760837
2/13/2007 8.706916548
2/14/2007 7.062821439
2/15/2007 6.720750572
2/16/2007 5.181412914
2/19/2007 6.377711852
2/20/2007 6.777151257
2/21/2007 7.213968623
2/22/2007 5.717975255
2/23/2007 7.535619266
2/26/2007 6.226846924
2/27/2007 6.420469572
2/28/2007 7.825909152
3/1/2007 9.322928614
3/2/2007 10.09251084
3/5/2007 10.01940332
3/6/2007 8.500303192
3/7/2007 8.276245994
3/8/2007 8.618637579
3/9/2007 9.130646064
3/12/2007 5.00975105
3/13/2007 3.332393527
3/14/2007 1.483827461
3/15/2007 3.638824916
3/16/2007 3.461569024
3/19/2007 2.163572694
3/20/2007 2.369195247
3/21/2007 -3.015080521
3/22/2007 -2.584981113
3/23/2007 1.616297026
3/26/2007 3.424344952
3/27/2007 3.512629879
3/28/2007 1.565564369
3/29/2007 3.155875359
3/30/2007 4.13585074
4/2/2007 2.121894843
4/3/2007 2.85329683
4/4/2007 2.790940846
4/5/2007 2.709380118
4/6/2007 -0.537294118
4/9/2007 1.409591457
4/10/2007 -0.844805873
4/11/2007 -3.199042638
4/12/2007 -5.222678135
4/13/2007 -5.360018022
4/16/2007 -4.086590776
4/17/2007 -6.846401327
4/18/2007 -8.129698699
4/19/2007 -9.43907148
4/20/2007 -9.54782865
4/23/2007 -10.0618768
4/24/2007 -7.849914365
4/25/2007 -8.470629566
4/26/2007 -8.241284473
4/27/2007 -5.784288072
4/30/2007 -6.333447193
5/1/2007 -8.855330907
5/2/2007 -8.631907451
5/3/2007 -9.548866116
5/4/2007 -10.13722709
5/7/2007 -11.32424337
5/8/2007 -13.57236374
5/9/2007 -11.50262124
5/10/2007 -10.80211768
5/11/2007 -10.26422821
5/14/2007 -8.986010695
5/15/2007 -10.63105462
5/16/2007 -12.91613223
5/17/2007 -10.43330955
5/18/2007 -10.07261057
5/21/2007 -12.94116388
5/22/2007 -11.97531943
5/23/2007 -12.58290308
5/24/2007 -12.94199083
5/25/2007 -14.38311469
5/28/2007 -13.28631254
5/29/2007 -12.89413624
5/30/2007 -16.04739138
5/31/2007 -13.83259156
6/1/2007 -14.26299611
6/4/2007 -14.99654576
6/5/2007 -13.24079702
6/6/2007 -12.01283208
6/7/2007 -12.58499189
6/8/2007 -10.50548575
6/11/2007 -13.46398497
6/12/2007 -10.95636348
6/13/2007 -10.58475154
6/14/2007 -8.485156989
6/15/2007 -5.485141673
6/18/2007 -4.746107027
6/19/2007 0.009767635
6/20/2007 -0.673658716
6/21/2007 -1.451419275
6/22/2007 1.972232158
6/25/2007 -0.391243872
6/26/2007 1.451989507
6/27/2007 -1.766451879
6/28/2007 0.161875559
6/29/2007 -3.825996412
7/2/2007 -0.809421674
7/3/2007 -2.246492588
7/4/2007 0.432136714
7/5/2007 0.283847174
7/6/2007 -1.3650488
7/9/2007 -0.811143411
7/10/2007 -1.465879459
7/11/2007 -1.121273878
7/12/2007 -1.860874059
7/13/2007 -3.035369125
7/16/2007 1.281001022
7/17/2007 1.690991572
7/18/2007 1.945639351
7/19/2007 1.069216233
7/20/2007 3.87371198
7/23/2007 3.296879921
7/24/2007 2.591854823
7/25/2007 -3.389010393
7/26/2007 2.137825455
7/27/2007 2.283479857
7/30/2007 5.838696664
7/31/2007 6.113554468
8/1/2007 7.967210681
8/2/2007 -0.726487682
8/3/2007 -0.232469303
8/6/2007 -2.517441263
8/7/2007 -8.435316702
8/8/2007 -4.850705516
8/9/2007 -6.961937954
8/10/2007 -10.44411748
8/13/2007 -15.68807076
8/14/2007 -13.18786164
8/15/2007 -9.272095703
8/16/2007 -4.725484174
8/17/2007 -8.134541843
8/20/2007 -8.873292727
8/21/2007 -10.55565794
8/22/2007 -9.78740166
8/23/2007 -8.392234748
8/24/2007 -11.26803991
8/27/2007 -6.059253076
8/28/2007 -4.431249471
8/29/2007 -3.683881225
8/30/2007 0.740388956
8/31/2007 0.837060926
9/3/2007 3.715197568
9/4/2007 2.014739847
9/5/2007 4.587444167
9/6/2007 3.221048769
9/7/2007 1.226037567
9/10/2007 1.034531855
9/11/2007 1.479676939
9/12/2007 0.556376215
9/13/2007 -1.530067312
9/14/2007 -2.18203607
9/17/2007 -5.475770938
9/18/2007 -6.824996518
9/19/2007 -2.973998241
9/20/2007 3.708296857
9/21/2007 -3.183077897
9/24/2007 -6.546095221
9/25/2007 -11.00709425
9/26/2007 -10.95480863
9/27/2007 -6.680893811
9/28/2007 -3.787250701
10/1/2007 -14.69643306
10/2/2007 -12.37222197
10/3/2007 -5.619971442
10/4/2007 -5.695837937
10/5/2007 -3.872021061
10/8/2007 -5.852564553
10/9/2007 -6.48262714
10/10/2007 -2.398114024
10/11/2007 -3.103357068
10/12/2007 -5.878634994
10/15/2007 -9.082817992
10/16/2007 -6.07416967
10/17/2007 -3.661138214
10/18/2007 -1.840354785
10/19/2007 -1.716032675
10/22/2007 -9.940732878
10/23/2007 -6.779819032
10/24/2007 -9.55117772
10/25/2007 -6.301075251
10/26/2007 -4.727985653
10/29/2007 -3.424320292
10/30/2007 -7.488285236
10/31/2007 -11.8982972
11/1/2007 -15.03925521
11/2/2007 -15.26744844
11/5/2007 -14.74166075
11/6/2007 -17.44941576
11/7/2007 -17.61279378
11/8/2007 -18.86796214
11/9/2007 -16.67827827
11/12/2007 -12.24014836
11/13/2007 -2.85835521
11/14/2007 -4.131716897
11/15/2007 -0.203410622
11/16/2007 8.569314879
11/19/2007 5.520498128
11/20/2007 4.437427097
11/21/2007 2.798799233
11/22/2007 5.190459646
11/23/2007 2.201222838
11/26/2007 7.707810591
11/27/2007 5.20689008
11/28/2007 7.610897036
11/29/2007 6.703331237
11/30/2007 13.92928613
12/3/2007 18.05895477
12/4/2007 17.24261674
12/5/2007 14.18520991
12/6/2007 17.69996813
12/7/2007 21.95404938
12/10/2007 18.57414126
12/11/2007 18.83884342
12/12/2007 22.41801362
12/13/2007 23.54638194
12/14/2007 25.76433638
12/17/2007 16.69320167
12/18/2007 10.81895687
12/19/2007 10.9753503
12/20/2007 11.33091315
12/21/2007 12.53094339
12/24/2007 14.45641754
12/25/2007 13.19699079
12/26/2007 13.87942316
12/27/2007 11.46173706
12/28/2007 7.770676488
12/31/2007 8.700784022
1/1/2008 14.19019359
1/2/2008 11.50921642
1/3/2008 9.467085019
1/4/2008 8.492617897
1/7/2008 5.371302597
1/8/2008 6.499502146
1/9/2008 3.022727189
1/10/2008 5.927807015
1/11/2008 5.001251384
1/14/2008 0.091578188
1/15/2008 6.806397951
1/16/2008 2.248016175
1/17/2008 5.749742329
1/18/2008 1.095388248
1/21/2008 -0.368023403
1/22/2008 8.237992918
1/23/2008 -0.780766435
1/24/2008 -0.233793677
1/25/2008 -5.104415967
1/28/2008 -5.638624718
1/29/2008 -2.511924819
1/30/2008 -2.133339717
1/31/2008 -3.014162532
2/1/2008 4.847211419
2/4/2008 1.90534583
2/5/2008 -0.089019867
2/6/2008 -3.930920283
2/7/2008 -7.596390602
2/8/2008 -5.358477963
2/11/2008 -3.588291865
2/12/2008 -1.031121178
2/13/2008 4.176705555
2/14/2008 4.100989501
2/15/2008 3.685820292
2/18/2008 3.918671965
2/19/2008 4.302039738
2/20/2008 8.143021699
2/21/2008 7.475478645
2/22/2008 2.322549449
2/25/2008 5.058904324
2/26/2008 0.911568809
2/27/2008 -1.720405845
2/28/2008 -4.566637975
2/29/2008 -7.874776755
3/3/2008 -7.949385894
3/4/2008 -7.987067299
3/5/2008 -12.40581822
3/6/2008 -9.860569783
3/7/2008 -12.72461433
3/10/2008 -11.14026753
3/11/2008 -6.222506019
3/12/2008 -2.083816629
3/13/2008 -1.722946088
3/14/2008 -5.537069436
3/17/2008 -6.716071481
3/18/2008 -6.693944594
3/19/2008 5.819147828
3/20/2008 9.65059264
3/21/2008 14.9915837
3/24/2008 14.39795771
3/25/2008 12.093442
3/26/2008 9.296061707
3/27/2008 12.99072309
3/28/2008 9.836902201
3/31/2008 9.921155178
4/1/2008 7.310883267
4/2/2008 14.15477406
4/3/2008 15.48242329
4/4/2008 7.464041165
4/7/2008 11.33508368
4/8/2008 15.59010551
4/9/2008 12.58380558
4/10/2008 14.61160039
4/11/2008 12.68080501
4/14/2008 11.06353488
4/15/2008 7.092636692
4/16/2008 7.592291792
4/17/2008 3.699266022
4/18/2008 5.928888483
4/21/2008 9.133551847
4/22/2008 6.211128385
4/23/2008 5.59943155
4/24/2008 11.19533502
4/25/2008 8.286268131
4/28/2008 10.85713699
4/29/2008 10.96304626
4/30/2008 9.392330251
5/1/2008 0.459398303
5/2/2008 6.634717801
5/5/2008 7.475896399
5/6/2008 6.934371007
5/7/2008 5.570514268
5/8/2008 6.270557437
5/9/2008 7.889956448
5/12/2008 1.34341901
5/13/2008 -1.824946933
5/14/2008 -1.801607848
5/15/2008 -2.846939297
5/16/2008 -2.62131888
5/19/2008 -2.663214031
5/20/2008 -3.774870813
5/21/2008 -5.138174533
5/22/2008 -5.480107155
5/23/2008 -6.670996157
5/26/2008 -4.64561419
5/27/2008 -4.145292498
5/28/2008 0.355057164
5/29/2008 -2.939764523
5/30/2008 -6.63747287
6/2/2008 -6.098950421
6/3/2008 -7.13882023
6/4/2008 -5.604616952
6/5/2008 -4.549857994
6/6/2008 5.087697562
6/9/2008 6.579771782
6/10/2008 0.060955293
6/11/2008 2.445348204
6/12/2008 0.317989372
6/13/2008 3.251865221
6/16/2008 6.862732095
6/17/2008 -0.134582166
6/18/2008 -6.537950835
6/19/2008 -8.448799147
6/20/2008 -6.732406995
6/23/2008 -7.738394975
6/24/2008 -8.206195168
6/25/2008 -5.548307148
6/26/2008 -7.002765304
6/27/2008 -6.495980763
6/30/2008 -8.8477976
7/1/2008 -1.679587243
7/2/2008 0.128504075
7/3/2008 -0.255570561
7/4/2008 3.108701207
7/7/2008 5.492404862
7/8/2008 3.133532773
7/9/2008 2.385568794
7/10/2008 -3.712475585
7/11/2008 -2.11874535
7/14/2008 -7.791149245
7/15/2008 -9.785882826
7/16/2008 -16.1405786
7/17/2008 -14.74751549
7/18/2008 -13.27703399
7/21/2008 -14.20650424
7/22/2008 -16.05642567
7/23/2008 -10.40258214
7/24/2008 -7.895783574
7/25/2008 -6.064576168
7/28/2008 -7.555469117
7/29/2008 -7.550365786
7/30/2008 -4.41096581
7/31/2008 0.972694457
8/1/2008 -3.909922199
8/4/2008 -2.854671378
8/5/2008 -4.752925064
8/6/2008 7.894333599
8/7/2008 6.952958366
8/8/2008 6.803337004
8/11/2008 12.5598522
8/12/2008 17.02711995
8/13/2008 11.21457308
8/14/2008 9.870340669
8/15/2008 13.52048273
8/18/2008 15.36663294
8/19/2008 12.06804629
8/20/2008 10.90150334
8/21/2008 9.740240549
8/22/2008 5.754842321
8/25/2008 5.094710468
8/26/2008 4.298242012
8/27/2008 3.633974039
8/28/2008 2.662183974
8/29/2008 2.274767726
9/1/2008 3.049897094
9/2/2008 3.728150019
9/3/2008 3.568469208
9/4/2008 3.118192613
9/5/2008 0.208336992
9/8/2008 -7.955346446
9/9/2008 3.034657287
9/10/2008 0.212924163
9/11/2008 -5.039089706
9/12/2008 -4.206315664
9/15/2008 -12.47329445
9/16/2008 -23.87744975
9/17/2008 -26.40484165
9/18/2008 -25.38241597
9/19/2008 -23.36121528
9/22/2008 -21.42741971
9/23/2008 -17.99846112
9/24/2008 -28.57986509
9/25/2008 -29.16609299
9/26/2008 -27.08038434
9/29/2008 -20.97454917
9/30/2008 -30.86583486
10/1/2008 -11.34463183
10/2/2008 -12.48376615
10/3/2008 -6.026656168
10/6/2008 -6.990288682
10/7/2008 -8.932722825
10/8/2008 -9.613027881
10/9/2008 -9.639879581
10/10/2008 -9.585152864
10/13/2008 -3.406342217
10/14/2008 8.128268033
10/15/2008 -0.84337937
10/16/2008 3.021563746
10/17/2008 -3.052518135
10/20/2008 -2.400985986
10/21/2008 3.0230433
10/22/2008 10.5804596
10/23/2008 18.09790623
10/24/2008 12.13621658
10/27/2008 14.20662326
10/28/2008 21.01635274
10/29/2008 17.2248841
10/30/2008 -4.561706872
10/31/2008 -18.90903769
11/3/2008 -4.608843616
11/4/2008 -20.06787313
11/5/2008 -18.5941511
11/6/2008 -21.3287201
11/7/2008 -18.90428072
11/10/2008 -17.15139132
11/11/2008 -11.95485141
11/12/2008 -10.52108832
11/13/2008 -3.751031577
11/14/2008 -7.025476067
11/17/2008 -0.484754776
11/18/2008 -7.565724121
11/19/2008 -3.494100907
11/20/2008 1.878346526
11/21/2008 8.620226332
11/24/2008 -2.178445463
11/25/2008 -6.594895809
11/26/2008 -13.80582831
11/27/2008 -1.718399396
11/28/2008 -2.690040888
12/1/2008 0.045615029
12/2/2008 -8.037898361
12/3/2008 -6.694808104
12/4/2008 -1.105754753
12/5/2008 1.02570118
12/8/2008 -4.239560375
12/9/2008 -5.393379841
12/10/2008 -2.751561124
12/11/2008 -2.779615506
12/12/2008 -3.187906517
12/15/2008 -1.152777608
12/16/2008 -8.701242176
12/17/2008 -17.74161255
12/18/2008 -25.91607496
12/19/2008 -23.78881822
12/22/2008 -21.24675823
12/23/2008 -11.96460548
12/24/2008 -15.00820918
12/25/2008 -18.71378165
12/26/2008 -15.66724025
12/29/2008 -9.785209077
12/30/2008 -8.555974407
12/31/2008 -8.218782102
import pandas as pd
df=read_csv("Randomdata.csv")
df2=df.add(1).cumprod()
I tried another method too.
df3=1+df.cumprod()
Both are yielding -inf values. It's happening for this data set specifically.
Please suggest the way forward.
It looks like you are trying to calculate cumulative returns. If so, those numbers are not in returns space and need to be divided by 100 first
import pandas as pd
df = pd.read_csv("Randomdata.csv")
df2 = df.div(100).add(1).cumprod().sub(1).mul(100)
Comment from OP
I made the following change, removed subtraction.
df2 = df.div(100).add(1).cumprod().mul(100)
df2['returns_from_price_recovered'] = 100 * df2.pct_change()

Find the closest numbers in a data set based on target data set

I have two data sets, group A has hundreds numbers and group B have eight numbers. I want to find another eight numbers in group A that are closest to the four numbers in group B. Now I take one number from group B each time and compared it with group A. Is there other better way to do this?
A = [762.859793, 763.544183, 764.272883, 766.190053, 767.108693, 767.123893, 768.933893, 770.619013, 771.375173, 771.522083, 774.9478730000001, 775.138843, 775.463863, 776.332693, 776.466303, 777.650083, 778.3751129999999, 781.922783, 782.592033, 784.224423, 784.779903, 785.2743429999999, 787.098133, 787.8258030000001, 787.8593030000001, 788.194393, 790.939383, 791.379753, 793.572803, 796.093073, 796.720693, 796.852473, 798.519643, 800.145803, 800.758723, 801.239613, 801.332453, 801.819333, 805.290823, 806.404353, 807.995663, 808.683403, 810.0645030000001, 810.695673, 810.7933929999999, 811.150203, 814.270803, 814.706783, 815.6527629999999, 819.127253, 819.820733, 821.030753, 821.166193, 823.111683, 824.637013, 826.707083, 826.997243, 827.441463, 828.529713, 830.364193, 831.241203, 831.2571929999999, 832.635243, 832.9749730000001, 834.222713, 837.932063, 838.250483, 838.695363, 840.0615730000001, 841.246143, 841.300043, 841.5062230000001, 844.7620730000001, 845.1879230000001, 846.261283, 847.139523, 849.0279429999999, 850.5646929999999, 850.726553, 851.8736529999999, 853.9559830000001, 854.171933, 857.674983, 858.035633, 858.327443, 858.9393230000001, 859.365103, 860.0646929999999, 861.035573, 861.496883, 864.127743, 866.558833, 867.0207429999999, 868.135673, 869.329093, 870.5860529999999, 871.1149230000001, 871.691343, 872.156483, 875.2681230000001, 875.921803, 876.6624029999999, 879.2358929999999, 879.7697029999999, 880.6190730000001, 882.563473, 883.1651529999999, 883.6522130000001, 884.311393, 886.585383, 888.0967929999999, 889.6549630000001, 890.564143, 891.0488230000001, 892.887933, 893.3944630000001, 896.817743, 897.9441429999999, 898.577573, 898.681813, 900.280573, 901.308643, 903.324453, 905.128653, 905.9143029999999, 906.190423, 906.641533, 907.232963, 909.896413, 912.3604630000001, 913.905633, 914.0172630000001, 915.186703, 915.764243, 917.266943, 921.000943, 921.958943, 923.0551429999999, 924.235543, 924.545743, 925.517043, 925.8717429999999, 927.906943, 931.119243, 931.856543, 933.8970429999999, 933.929043, 934.2806429999999, 935.171843, 936.956243, 938.8980429999999, 941.066643, 941.633743, 942.986043, 944.437243, 945.839343, 948.351143, 949.9056429999999, 950.118243, 950.587543, 951.3468429999999, 954.000243, 954.205843, 954.944843, 955.703343, 959.0683429999999, 959.298543, 960.0447429999999, 961.379543, 965.161943, 967.108743, 967.7327429999999, 968.199043, 968.438843, 969.973543, 970.540543, 971.3676429999999, 972.284543, 973.603743, 976.753143, 978.1982429999999, 978.214943, 978.545843, 979.070643, 980.912243, 982.989643, 985.355943, 986.1942429999999, 986.3504429999999, 986.4826429999999, 988.964343, 989.596543, 992.602043, 993.117943, 993.7612429999999, 994.3083429999999, 994.401343, 995.340643, 998.5397429999999, 999.000443, 1000.593343, 1000.6357429999999, 1001.2584429999999, 1001.334243, 1003.663543, 1004.3092429999999, 1006.184043, 1006.665143, 1007.890843, 1010.872443, 1011.4528429999999, 1012.454843, 1012.648543, 1012.825443, 1013.512643, 1015.107543, 1017.5950429999999, 1018.145843, 1022.399143, 1023.348243, 1023.4881429999999, 1023.703943, 1023.892743, 1024.563343, 1026.059343, 1028.420643, 1028.633143, 1028.928743, 1029.316843, 1032.945843, 1036.954843, 1037.770843, 1038.025643, 1039.704743, 1040.994643, 1041.791843, 1042.953943, 1043.592843, 1043.708343, 1050.5268429999999, 1052.079443, 1052.649543, 1052.684943, 1055.256443, 1060.528543, 1061.940143, 1062.041143, 1065.194343, 1065.722143, 1066.910543, 1068.947743, 1073.2487429999999, 1073.632343, 1074.822043, 1075.200543, 1076.141143, 1077.981343, 1079.280243, 1081.3022429999999, 1081.893343, 1085.848643, 1086.145043, 1087.4752429999999, 1087.7197429999999, 1089.479843, 1094.0820429999999, 1094.511343, 1094.685543, 1096.808443, 1097.674643, 1100.9245429999999, 1101.318843, 1101.795743, 1106.028343, 1106.752143, 1108.441043, 1109.063443, 1110.809843, 1112.244343, 1115.205043, 1115.793543, 1116.281043, 1117.533043, 1120.772743, 1120.943343, 1122.063243, 1126.348043, 1126.588843, 1127.782343, 1127.8493429999999, 1132.284543, 1133.968643, 1134.083643, 1134.812743, 1138.425743, 1140.277243, 1142.692943, 1143.479343, 1143.508343, 1146.1264429999999, 1147.5087429999999, 1148.0667429999999, 1149.901943, 1150.083443, 1154.467843, 1155.7469429999999, 1156.378443, 1157.213743, 1157.893943, 1161.299843, 1163.574343, 1165.368743, 1166.530043, 1167.6391429999999, 1168.554843, 1169.4887429999999, 1170.586043, 1175.934543, 1178.156243, 1178.610543, 1178.921943, 1179.145843, 1179.573643, 1187.012243, 1187.262843, 1187.406943, 1189.229243, 1191.636343, 1191.886343, 1194.272843, 1195.991843, 1199.937643, 1200.047843, 1201.449543, 1204.830543, 1205.389743, 1209.462843, 1210.561743, 1212.594143, 1213.386543, 1214.1418429999999, 1214.154443, 1219.073643, 1221.015143, 1222.636843, 1223.881443, 1227.9897429999999, 1228.923443, 1229.525743, 1233.922243, 1234.473743, 1235.452343, 1235.808943, 1240.449043, 1241.093643, 1245.171843, 1245.478243, 1246.061043, 1246.452043, 1249.927343, 1252.341943, 1255.264743, 1257.632643, 1258.441243, 1258.452643, 1259.841943, 1260.042343, 1265.0739429999999, 1266.0141429999999, 1267.6002429999999, 1269.445043, 1270.469243, 1274.139643, 1274.924043, 1276.423843, 1281.449543, 1283.915543, 1284.392443, 1284.828943, 1287.5820429999999, 1288.2985429999999, 1290.2225429999999, 1290.778043, 1294.631843, 1296.719843, 1298.903343, 1301.526443, 1302.276343, 1302.490343, 1303.954143, 1309.437843, 1310.548043, 1314.348243, 1316.070543, 1316.260843, 1317.751243, 1317.935543, 1322.146643, 1328.689343, 1329.097243, 1329.546543, 1329.820643, 1333.801543, 1334.257043, 1338.509343, 1338.584243, 1339.321543, 1341.807143, 1345.492643, 1347.315443, 1348.668043, 1349.854643, 1352.199543, 1352.210943, 1356.886143, 1358.197243, 1361.030843, 1362.906043, 1364.2469429999999, 1366.268943, 1369.804343, 1374.347243, 1374.5440429999999, 1374.9235429999999, 1375.318443, 1377.875843, 1380.191043, 1381.156143, 1387.996743, 1388.038843, 1388.494543, 1390.815443, 1391.645243, 1397.819343, 1398.548343, 1399.623443, 1400.494943, 1402.532943, ]
B = [679.070505, 1358.141011]
Sort data set A
For each element of B (call it b)
Use a binary search (or interpolation search) to find where b would fit into A.
That gives you two adjacent indices; one number is larger than b, one smaller.
Choose the number of the two closer to b.
Does that get you going?
With NumPy arrays and vectorised operations:
import numpy as np
A = np.array(A)
B = np.array(B)
idx = np.abs(A - B[:, None]).argmin(1)
res = A[idx]
print(res)
array([ 762.859793, 1358.197243])
You can pre-process your long list in order to calculate the middle value between adjacent pairs. Then, you can use bisect to obtain the index of the closest number:
from bisect import bisect
A = (762.859793, 763.544183, 764.272883, 766.190053, 767.108693, 767.123893, 768.933893, 770.619013, 771.375173, 771.522083, 774.9478730000001, 775.138843, 775.463863, 776.332693, 776.466303, 777.650083, 778.3751129999999, 781.922783, 782.592033, 784.224423, 784.779903, 785.2743429999999, 787.098133, 787.8258030000001, 787.8593030000001, 788.194393, 790.939383, 791.379753, 793.572803, 796.093073, 796.720693, 796.852473, 798.519643, 800.145803, 800.758723, 801.239613, 801.332453, 801.819333, 805.290823, 806.404353, 807.995663, 808.683403, 810.0645030000001, 810.695673, 810.7933929999999, 811.150203, 814.270803, 814.706783, 815.6527629999999, 819.127253, 819.820733, 821.030753, 821.166193, 823.111683, 824.637013, 826.707083, 826.997243, 827.441463, 828.529713, 830.364193, 831.241203, 831.2571929999999, 832.635243, 832.9749730000001, 834.222713, 837.932063, 838.250483, 838.695363, 840.0615730000001, 841.246143, 841.300043, 841.5062230000001, 844.7620730000001, 845.1879230000001, 846.261283, 847.139523, 849.0279429999999, 850.5646929999999, 850.726553, 851.8736529999999, 853.9559830000001, 854.171933, 857.674983, 858.035633, 858.327443, 858.9393230000001, 859.365103, 860.0646929999999, 861.035573, 861.496883, 864.127743, 866.558833, 867.0207429999999, 868.135673, 869.329093, 870.5860529999999, 871.1149230000001, 871.691343, 872.156483, 875.2681230000001, 875.921803, 876.6624029999999, 879.2358929999999, 879.7697029999999, 880.6190730000001, 882.563473, 883.1651529999999, 883.6522130000001, 884.311393, 886.585383, 888.0967929999999, 889.6549630000001, 890.564143, 891.0488230000001, 892.887933, 893.3944630000001, 896.817743, 897.9441429999999, 898.577573, 898.681813, 900.280573, 901.308643, 903.324453, 905.128653, 905.9143029999999, 906.190423, 906.641533, 907.232963, 909.896413, 912.3604630000001, 913.905633, 914.0172630000001, 915.186703, 915.764243, 917.266943, 921.000943, 921.958943, 923.0551429999999, 924.235543, 924.545743, 925.517043, 925.8717429999999, 927.906943, 931.119243, 931.856543, 933.8970429999999, 933.929043, 934.2806429999999, 935.171843, 936.956243, 938.8980429999999, 941.066643, 941.633743, 942.986043, 944.437243, 945.839343, 948.351143, 949.9056429999999, 950.118243, 950.587543, 951.3468429999999, 954.000243, 954.205843, 954.944843, 955.703343, 959.0683429999999, 959.298543, 960.0447429999999, 961.379543, 965.161943, 967.108743, 967.7327429999999, 968.199043, 968.438843, 969.973543, 970.540543, 971.3676429999999, 972.284543, 973.603743, 976.753143, 978.1982429999999, 978.214943, 978.545843, 979.070643, 980.912243, 982.989643, 985.355943, 986.1942429999999, 986.3504429999999, 986.4826429999999, 988.964343, 989.596543, 992.602043, 993.117943, 993.7612429999999, 994.3083429999999, 994.401343, 995.340643, 998.5397429999999, 999.000443, 1000.593343, 1000.6357429999999, 1001.2584429999999, 1001.334243, 1003.663543, 1004.3092429999999, 1006.184043, 1006.665143, 1007.890843, 1010.872443, 1011.4528429999999, 1012.454843, 1012.648543, 1012.825443, 1013.512643, 1015.107543, 1017.5950429999999, 1018.145843, 1022.399143, 1023.348243, 1023.4881429999999, 1023.703943, 1023.892743, 1024.563343, 1026.059343, 1028.420643, 1028.633143, 1028.928743, 1029.316843, 1032.945843, 1036.954843, 1037.770843, 1038.025643, 1039.704743, 1040.994643, 1041.791843, 1042.953943, 1043.592843, 1043.708343, 1050.5268429999999, 1052.079443, 1052.649543, 1052.684943, 1055.256443, 1060.528543, 1061.940143, 1062.041143, 1065.194343, 1065.722143, 1066.910543, 1068.947743, 1073.2487429999999, 1073.632343, 1074.822043, 1075.200543, 1076.141143, 1077.981343, 1079.280243, 1081.3022429999999, 1081.893343, 1085.848643, 1086.145043, 1087.4752429999999, 1087.7197429999999, 1089.479843, 1094.0820429999999, 1094.511343, 1094.685543, 1096.808443, 1097.674643, 1100.9245429999999, 1101.318843, 1101.795743, 1106.028343, 1106.752143, 1108.441043, 1109.063443, 1110.809843, 1112.244343, 1115.205043, 1115.793543, 1116.281043, 1117.533043, 1120.772743, 1120.943343, 1122.063243, 1126.348043, 1126.588843, 1127.782343, 1127.8493429999999, 1132.284543, 1133.968643, 1134.083643, 1134.812743, 1138.425743, 1140.277243, 1142.692943, 1143.479343, 1143.508343, 1146.1264429999999, 1147.5087429999999, 1148.0667429999999, 1149.901943, 1150.083443, 1154.467843, 1155.7469429999999, 1156.378443, 1157.213743, 1157.893943, 1161.299843, 1163.574343, 1165.368743, 1166.530043, 1167.6391429999999, 1168.554843, 1169.4887429999999, 1170.586043, 1175.934543, 1178.156243, 1178.610543, 1178.921943, 1179.145843, 1179.573643, 1187.012243, 1187.262843, 1187.406943, 1189.229243, 1191.636343, 1191.886343, 1194.272843, 1195.991843, 1199.937643, 1200.047843, 1201.449543, 1204.830543, 1205.389743, 1209.462843, 1210.561743, 1212.594143, 1213.386543, 1214.1418429999999, 1214.154443, 1219.073643, 1221.015143, 1222.636843, 1223.881443, 1227.9897429999999, 1228.923443, 1229.525743, 1233.922243, 1234.473743, 1235.452343, 1235.808943, 1240.449043, 1241.093643, 1245.171843, 1245.478243, 1246.061043, 1246.452043, 1249.927343, 1252.341943, 1255.264743, 1257.632643, 1258.441243, 1258.452643, 1259.841943, 1260.042343, 1265.0739429999999, 1266.0141429999999, 1267.6002429999999, 1269.445043, 1270.469243, 1274.139643, 1274.924043, 1276.423843, 1281.449543, 1283.915543, 1284.392443, 1284.828943, 1287.5820429999999, 1288.2985429999999, 1290.2225429999999, 1290.778043, 1294.631843, 1296.719843, 1298.903343, 1301.526443, 1302.276343, 1302.490343, 1303.954143, 1309.437843, 1310.548043, 1314.348243, 1316.070543, 1316.260843, 1317.751243, 1317.935543, 1322.146643, 1328.689343, 1329.097243, 1329.546543, 1329.820643, 1333.801543, 1334.257043, 1338.509343, 1338.584243, 1339.321543, 1341.807143, 1345.492643, 1347.315443, 1348.668043, 1349.854643, 1352.199543, 1352.210943, 1356.886143, 1358.197243, 1361.030843, 1362.906043, 1364.2469429999999, 1366.268943, 1369.804343, 1374.347243, 1374.5440429999999, 1374.9235429999999, 1375.318443, 1377.875843, 1380.191043, 1381.156143, 1387.996743, 1388.038843, 1388.494543, 1390.815443, 1391.645243, 1397.819343, 1398.548343, 1399.623443, 1400.494943, 1402.532943, )
B = (679.070505, 763, 1358.141011, 4000)
# A seems to be already sorted, otherwise we would have to sort it
# first
middles = [(A[i] + A[i+1])/2 for i in range(len(A)-1) ]
closest = [A[bisect(middles, value)] for value in B]
print(closest)
# [762.859793, 762.859793, 1358.197243, 1402.532943]
bisect(middles, value) will return the index at which you would have to insert value in the list of middles, such that it will be just between two middle values. This way, it is guaranteed to be closest to the value between these middles.
The creation of the middles list is O(size of A), each subsequent use of bisect will be rather fast as it uses a bisection algorithm.
Make a list of pairs, (difference, number) for each element in B. For each item in A, compute its difference with each item in B and if that difference is smaller than the stored one, replace the stored data.
A = (762.859793, 763.544183, 764.272883, 766.190053, 767.108693, 767.123893, 768.933893, 770.619013, 771.375173, 771.522083, 774.9478730000001, 775.138843, 775.463863, 776.332693, 776.466303, 777.650083, 778.3751129999999, 781.922783, 782.592033, 784.224423, 784.779903, 785.2743429999999, 787.098133, 787.8258030000001, 787.8593030000001, 788.194393, 790.939383, 791.379753, 793.572803, 796.093073, 796.720693, 796.852473, 798.519643, 800.145803, 800.758723, 801.239613, 801.332453, 801.819333, 805.290823, 806.404353, 807.995663, 808.683403, 810.0645030000001, 810.695673, 810.7933929999999, 811.150203, 814.270803, 814.706783, 815.6527629999999, 819.127253, 819.820733, 821.030753, 821.166193, 823.111683, 824.637013, 826.707083, 826.997243, 827.441463, 828.529713, 830.364193, 831.241203, 831.2571929999999, 832.635243, 832.9749730000001, 834.222713, 837.932063, 838.250483, 838.695363, 840.0615730000001, 841.246143, 841.300043, 841.5062230000001, 844.7620730000001, 845.1879230000001, 846.261283, 847.139523, 849.0279429999999, 850.5646929999999, 850.726553, 851.8736529999999, 853.9559830000001, 854.171933, 857.674983, 858.035633, 858.327443, 858.9393230000001, 859.365103, 860.0646929999999, 861.035573, 861.496883, 864.127743, 866.558833, 867.0207429999999, 868.135673, 869.329093, 870.5860529999999, 871.1149230000001, 871.691343, 872.156483, 875.2681230000001, 875.921803, 876.6624029999999, 879.2358929999999, 879.7697029999999, 880.6190730000001, 882.563473, 883.1651529999999, 883.6522130000001, 884.311393, 886.585383, 888.0967929999999, 889.6549630000001, 890.564143, 891.0488230000001, 892.887933, 893.3944630000001, 896.817743, 897.9441429999999, 898.577573, 898.681813, 900.280573, 901.308643, 903.324453, 905.128653, 905.9143029999999, 906.190423, 906.641533, 907.232963, 909.896413, 912.3604630000001, 913.905633, 914.0172630000001, 915.186703, 915.764243, 917.266943, 921.000943, 921.958943, 923.0551429999999, 924.235543, 924.545743, 925.517043, 925.8717429999999, 927.906943, 931.119243, 931.856543, 933.8970429999999, 933.929043, 934.2806429999999, 935.171843, 936.956243, 938.8980429999999, 941.066643, 941.633743, 942.986043, 944.437243, 945.839343, 948.351143, 949.9056429999999, 950.118243, 950.587543, 951.3468429999999, 954.000243, 954.205843, 954.944843, 955.703343, 959.0683429999999, 959.298543, 960.0447429999999, 961.379543, 965.161943, 967.108743, 967.7327429999999, 968.199043, 968.438843, 969.973543, 970.540543, 971.3676429999999, 972.284543, 973.603743, 976.753143, 978.1982429999999, 978.214943, 978.545843, 979.070643, 980.912243, 982.989643, 985.355943, 986.1942429999999, 986.3504429999999, 986.4826429999999, 988.964343, 989.596543, 992.602043, 993.117943, 993.7612429999999, 994.3083429999999, 994.401343, 995.340643, 998.5397429999999, 999.000443, 1000.593343, 1000.6357429999999, 1001.2584429999999, 1001.334243, 1003.663543, 1004.3092429999999, 1006.184043, 1006.665143, 1007.890843, 1010.872443, 1011.4528429999999, 1012.454843, 1012.648543, 1012.825443, 1013.512643, 1015.107543, 1017.5950429999999, 1018.145843, 1022.399143, 1023.348243, 1023.4881429999999, 1023.703943, 1023.892743, 1024.563343, 1026.059343, 1028.420643, 1028.633143, 1028.928743, 1029.316843, 1032.945843, 1036.954843, 1037.770843, 1038.025643, 1039.704743, 1040.994643, 1041.791843, 1042.953943, 1043.592843, 1043.708343, 1050.5268429999999, 1052.079443, 1052.649543, 1052.684943, 1055.256443, 1060.528543, 1061.940143, 1062.041143, 1065.194343, 1065.722143, 1066.910543, 1068.947743, 1073.2487429999999, 1073.632343, 1074.822043, 1075.200543, 1076.141143, 1077.981343, 1079.280243, 1081.3022429999999, 1081.893343, 1085.848643, 1086.145043, 1087.4752429999999, 1087.7197429999999, 1089.479843, 1094.0820429999999, 1094.511343, 1094.685543, 1096.808443, 1097.674643, 1100.9245429999999, 1101.318843, 1101.795743, 1106.028343, 1106.752143, 1108.441043, 1109.063443, 1110.809843, 1112.244343, 1115.205043, 1115.793543, 1116.281043, 1117.533043, 1120.772743, 1120.943343, 1122.063243, 1126.348043, 1126.588843, 1127.782343, 1127.8493429999999, 1132.284543, 1133.968643, 1134.083643, 1134.812743, 1138.425743, 1140.277243, 1142.692943, 1143.479343, 1143.508343, 1146.1264429999999, 1147.5087429999999, 1148.0667429999999, 1149.901943, 1150.083443, 1154.467843, 1155.7469429999999, 1156.378443, 1157.213743, 1157.893943, 1161.299843, 1163.574343, 1165.368743, 1166.530043, 1167.6391429999999, 1168.554843, 1169.4887429999999, 1170.586043, 1175.934543, 1178.156243, 1178.610543, 1178.921943, 1179.145843, 1179.573643, 1187.012243, 1187.262843, 1187.406943, 1189.229243, 1191.636343, 1191.886343, 1194.272843, 1195.991843, 1199.937643, 1200.047843, 1201.449543, 1204.830543, 1205.389743, 1209.462843, 1210.561743, 1212.594143, 1213.386543, 1214.1418429999999, 1214.154443, 1219.073643, 1221.015143, 1222.636843, 1223.881443, 1227.9897429999999, 1228.923443, 1229.525743, 1233.922243, 1234.473743, 1235.452343, 1235.808943, 1240.449043, 1241.093643, 1245.171843, 1245.478243, 1246.061043, 1246.452043, 1249.927343, 1252.341943, 1255.264743, 1257.632643, 1258.441243, 1258.452643, 1259.841943, 1260.042343, 1265.0739429999999, 1266.0141429999999, 1267.6002429999999, 1269.445043, 1270.469243, 1274.139643, 1274.924043, 1276.423843, 1281.449543, 1283.915543, 1284.392443, 1284.828943, 1287.5820429999999, 1288.2985429999999, 1290.2225429999999, 1290.778043, 1294.631843, 1296.719843, 1298.903343, 1301.526443, 1302.276343, 1302.490343, 1303.954143, 1309.437843, 1310.548043, 1314.348243, 1316.070543, 1316.260843, 1317.751243, 1317.935543, 1322.146643, 1328.689343, 1329.097243, 1329.546543, 1329.820643, 1333.801543, 1334.257043, 1338.509343, 1338.584243, 1339.321543, 1341.807143, 1345.492643, 1347.315443, 1348.668043, 1349.854643, 1352.199543, 1352.210943, 1356.886143, 1358.197243, 1361.030843, 1362.906043, 1364.2469429999999, 1366.268943, 1369.804343, 1374.347243, 1374.5440429999999, 1374.9235429999999, 1375.318443, 1377.875843, 1380.191043, 1381.156143, 1387.996743, 1388.038843, 1388.494543, 1390.815443, 1391.645243, 1397.819343, 1398.548343, 1399.623443, 1400.494943, 1402.532943, )
B = (679.070505, 1358.141011)
stored = [(float('inf'), None)]*len(B)
for a in A:
for i, ((curr_diff, _), b) in enumerate(zip(stored, B)):
diff = abs(a-b)
if diff < curr_diff:
stored[i] = (diff, a)
This gives me
[(83.78928799999994, 762.859793), (0.056232000000136395, 1358.197243)]

R DTW multivariate series with asymmetric step fails to compute alignment

I'm using the DTW implementation found in R along with the python bindings in order to verify the effects of changing different parameters(like local constraint, local distance function and others) for my data. The data represents feature vectors that an audio processing frontend outputs(MFCC). Because of this I am dealing with multivariate time series, each feature vector has a size of 8. The problem I'm facing is when I try to use certain local constraints ( or step patterns ) I get the following error:
Error in if (is.na(gcm$distance)) { : argument is of length zero
Traceback (most recent call last):
File "r_dtw_simplified.py", line 32, in <module>
alignment = R.dtw(canDist, rNull, "Euclidean", stepPattern, "none", True, Fa
lse, True, False )
File "D:\Python27\lib\site-packages\rpy2\robjects\functions.py", line 86, in _
_call__
return super(SignatureTranslatedFunction, self).__call__(*args, **kwargs)
File "D:\Python27\lib\site-packages\rpy2\robjects\functions.py", line 35, in _
_call__
res = super(Function, self).__call__(*new_args, **new_kwargs)
rpy2.rinterface.RRuntimeError: Error in if (is.na(gcm$distance)) { : argument is
of length zero
Because the process of generating and adapting the input data is complicated I only made a simplified script to ilustrate the error i'm receiving.
#data works
#reference = [[-0.126678, -1.541763, 0.29985, 1.719757, 0.755798, -3.594681, -1.492798, 3.493042], [-0.110596, -1.638184, 0.128174, 1.638947, 0.721085, -3.247696, -0.920013, 3.763977], [-0.022415, -1.643539, -0.130692, 1.441742, 1.022064, -2.882172, -0.952225, 3.662842], [0.071259, -2.030411, -0.531891, 0.835114, 1.320419, -2.432281, -0.469116, 3.871094], [0.070526, -2.056702, -0.688293, 0.530396, 1.962128, -1.681915, -0.368973, 4.542419], [0.047745, -2.005127, -0.798203, 0.616028, 2.146988, -1.895874, 0.371597, 4.090881], [0.013962, -2.162796, -1.008545, 0.363495, 2.062866, -0.856613, 0.543884, 4.043335], [0.066757, -2.152969, -1.087097, 0.257263, 2.592697, -0.422424, -0.280533, 3.327576], [0.123123, -2.061035, -1.012863, 0.389282, 2.50206, 0.078186, -0.887711, 2.828247], [0.157455, -2.060425, -0.790344, 0.210419, 2.542114, 0.016983, -0.959274, 1.916504], [0.029648, -2.128204, -1.047318, 0.116547, 2.44899, 0.166534, -0.677551, 2.49231], [0.158554, -1.821365, -1.045044, 0.374207, 2.426712, 0.406952, -1.055084, 2.543762], [0.077026, -1.863235, -1.14827, 0.277069, 2.669067, 0.362549, -1.294342, 1.66748], [0.101822, -1.800293, -1.126801, 0.364594, 2.503815, 0.294846, -0.881302, 1.281616], [0.166138, -1.627762, -0.866013, 0.494476, 2.450668, 0.569, -1.392868, 0.651184], [0.225006, -1.596069, -1.07634, 0.550049, 2.167435, 0.554123, -1.432983, 1.166931], [0.114777, -1.462769, -0.793167, 0.565704, 2.183792, 0.345978, -1.410919, 0.708679], [0.144028, -1.444458, -0.831985, 0.536652, 2.222366, 0.330368, -0.715149, 0.517212], [0.147888, -1.450577, -0.809372, 0.479584, 2.271378, 0.250763, -0.540359, -0.036072], [0.090714, -1.485474, -0.888153, 0.268768, 2.001221, 0.412537, -0.698868, 0.17157], [0.11972, -1.382767, -0.890457, 0.218414, 1.666519, 0.659592, -0.069641, 0.914307], [0.189774, -1.18428, -0.785797, 0.106659, 1.429977, 0.195236, 0.627029, 0.503296], [0.194702, -1.098068, -0.956818, 0.020386, 1.369247, 0.10437, 0.641724, 0.410767], [0.215134, -1.069092, -1.11644, 0.283234, 1.313507, 0.110962, 0.600861, 0.752869], [0.216766, -1.065338, -1.047974, 0.080231, 1.500702, -0.113388, 0.712646, 0.914307], [0.259933, -0.964386, -0.981369, 0.092224, 1.480667, -0.00238, 0.896255, 0.665344], [0.265991, -0.935257, -0.93779, 0.214966, 1.235275, 0.104782, 1.33754, 0.599487], [0.266098, -0.62619, -0.905792, 0.131409, 0.402908, 0.103363, 1.352814, 1.554688], [0.273468, -0.354691, -0.709579, 0.228027, 0.315125, -0.15564, 0.942123, 1.024292], [0.246429, -0.272522, -0.609924, 0.318604, -0.007355, -0.165756, 1.07019, 1.087708], [0.248596, -0.232468, -0.524887, 0.53009, -0.476334, -0.184479, 1.088089, 0.667358], [0.074478, -0.200455, -0.058411, 0.662811, -0.111923, -0.686462, 1.205154, 1.271912], [0.063065, -0.080765, 0.065552, 0.79071, -0.569946, -0.899506, 0.875687, 0.095215], [0.117706, -0.270584, -0.021027, 0.723694, -0.200073, -0.365158, 0.892624, -0.152466], [0.00148, -0.075348, 0.017761, 0.757507, 0.719299, -0.355362, 0.749329, 0.315247], [0.035034, -0.110794, 0.038559, 0.949677, 0.478699, 0.005951, 0.097305, -0.388245], [-0.101944, -0.392487, 0.401886, 1.154938, 0.199127, 0.117371, -0.070007, -0.562439], [-0.083282, -0.388657, 0.449066, 1.505951, 0.46405, -0.566208, 0.216293, -0.528076], [-0.152054, -0.100113, 0.833054, 1.746857, 0.085861, -1.314102, 0.294632, -0.470947], [-0.166672, -0.183777, 0.988373, 1.925262, -0.202057, -0.961441, 0.15242, 0.594421], [-0.234573, -0.227707, 1.102112, 1.802002, -0.382492, -1.153336, 0.29335, 0.074036], [-0.336426, 0.042435, 1.255096, 1.804535, -0.610153, -0.810745, 1.308441, 0.599854], [-0.359344, 0.007248, 1.344543, 1.441559, -0.758286, -0.800079, 1.0233, 0.668213], [-0.321823, 0.027618, 1.1521, 1.509827, -0.708267, -0.668152, 1.05722, 0.710571], [-0.265335, 0.012344, 1.491501, 1.844971, -0.584137, -1.042419, -0.449188, 0.5354], [-0.302399, 0.049698, 1.440643, 1.674866, -0.626633, -1.158554, -0.906937, 0.405579], [-0.330276, 0.466675, 1.444153, 0.855499, -0.645447, -0.352158, 0.730423, 0.429932], [-0.354721, 0.540207, 1.570786, 0.626648, -0.897446, -0.007416, 0.174042, 0.100525], [-0.239609, 0.669983, 0.978851, 0.85321, -0.156784, 0.107986, 0.915054, 0.114197], [-0.189346, 0.930756, 0.824295, 0.516083, -0.339767, -0.206314, 0.744049, -0.36377]]
#query = [[0.387268, -1.21701, -0.432266, -1.394104, -0.458984, -1.469788, 0.12764, 2.310059], [0.418091, -1.389526, -0.150146, -0.759155, -0.578003, -2.123199, 0.276001, 3.022339], [0.264694, -1.526886, -0.238907, -0.511108, -0.90683, -2.699249, 0.692032, 2.849854], [0.246628, -1.675171, -0.533432, 0.070007, -0.392151, -1.739227, 0.534485, 2.744019], [0.099335, -1.983826, -0.985291, 0.428833, 0.26535, -1.285583, -0.234451, 2.4729], [0.055893, -2.108063, -0.401825, 0.860413, 0.724106, -1.959137, -1.360458, 2.350708], [-0.131592, -1.928314, -0.056213, 0.577698, 0.859146, -1.812286, -1.21669, 2.2052], [-0.162796, -2.149933, 0.467239, 0.524231, 0.74913, -1.829498, -0.741913, 1.616577], [-0.282745, -1.971008, 0.837616, 0.56427, 0.198288, -1.826935, -0.118027, 1.599731], [-0.497223, -1.578705, 1.277298, 0.682983, 0.055084, -2.032562, 0.64151, 1.719238], [-0.634232, -1.433258, 1.760513, 0.550415, -0.053787, -2.188568, 1.666687, 1.611938], [-0.607498, -1.302826, 1.960556, 1.331726, 0.417633, -2.271973, 2.095001, 0.9823], [-0.952957, -0.222076, 0.772064, 2.062256, -0.295258, -1.255371, 3.450974, -0.047607], [-1.210587, 1.00061, 0.036392, 1.952209, 0.470123, 0.231628, 2.670502, -0.608276], [-1.213287, 0.927002, -0.414825, 2.104065, 1.160126, 0.088898, 1.32959, -0.018311], [-1.081558, 1.007751, -0.337509, 1.7146, 0.653687, 0.297089, 1.916733, -0.772461], [-1.064804, 1.284302, -0.393585, 2.150635, 0.132294, 0.443298, 1.967575, 0.775513], [-0.972366, 1.039734, -0.588135, 1.413818, 0.423813, 0.781494, 1.977509, -0.556274], [-0.556381, 0.591309, -0.678314, 1.025635, 1.094284, 2.234711, 1.504013, -1.71875], [-0.063477, 0.626129, 0.360489, 0.149902, 0.92804, 0.936493, 1.203018, 0.264282], [0.162003, 0.577698, 0.956863, -0.477051, 1.081161, 0.817749, 0.660843, -0.428711], [-0.049515, 0.423615, 0.82489, 0.446228, 1.323853, 0.562775, -0.144196, 1.145386], [-0.146851, 0.171906, 0.304871, 0.320435, 1.378937, 0.673004, 0.188416, 0.208618], [0.33992, -2.072418, -0.447968, 0.526794, -0.175858, -1.400299, -0.452454, 1.396606], [0.226089, -2.183441, -0.301071, -0.475159, 0.834961, -2.191864, -1.092361, 2.434814], [0.279556, -2.073181, -0.517639, -0.766479, 0.974808, -2.070374, -2.003891, 2.706421], [0.237961, -1.9245, -0.708435, -0.582153, 1.285934, -1.75882, -2.146164, 2.369995], [0.149658, -1.703705, -0.539749, -0.215332, 1.369705, -1.484802, -1.506256, 1.04126], [0.078735, -1.719543, 0.157013, 0.382385, 1.100998, -0.223755, 0.021683, -0.545654], [0.106003, -1.404358, 0.372345, 1.881165, -0.292511, -0.263855, 1.579529, -1.426025], [0.047729, -1.198608, 0.600769, 1.901123, -1.106949, 0.128815, 1.293701, -1.364258], [0.110748, -0.894348, 0.712601, 1.728699, -1.250381, 0.674377, 0.812302, -1.428833], [0.085754, -0.662903, 0.794312, 1.102844, -1.234283, 1.084442, 0.986938, -1.10022], [0.140823, -0.300323, 0.673508, 0.669983, -0.551453, 1.213074, 1.449326, -1.567261], [0.03743, 0.550293, 0.400909, -0.174622, 0.355301, 1.325867, 0.875854, 0.126953], [-0.084885, 1.128906, 0.292099, -0.248779, 0.722961, 0.873871, -0.409515, 0.470581], [0.019684, 0.947754, 0.19931, -0.306274, 0.176849, 1.431702, 1.091507, 0.701416], [-0.094162, 0.895203, 0.687378, -0.229065, 0.549088, 1.376953, 0.892303, -0.642334], [-0.727692, 0.626495, 0.848877, 0.521362, 1.521912, -0.443481, 1.247238, 0.197388], [-0.82048, 0.117279, 0.975174, 1.487244, 1.085281, -0.567993, 0.776093, -0.381592], [-0.009827, -0.553009, -0.213135, 0.837341, 0.482712, -0.939423, 0.140884, 0.330566], [-0.018127, -1.362335, -0.199265, 1.260742, 0.005188, -1.445068, -1.159653, 1.220825], [0.186172, -1.727814, -0.246552, 1.544128, 0.285416, 0.081848, -1.634003, -0.47522], [0.193649, -1.144043, -0.334854, 1.220276, 1.241302, 1.554382, 0.57048, -1.334961], [0.344604, -1.647461, -0.720749, 0.993774, 0.585709, 0.953522, -0.493042, -1.845703], [0.37471, -1.989471, -0.518555, 0.555908, -0.025787, 0.148132, -1.463425, -0.844849], [0.34523, -1.821625, -0.809418, 0.59137, -0.577927, 0.037903, -2.067764, -0.519531], [0.413193, -1.503876, -0.752243, 0.280396, -0.236206, 0.429932, -1.684097, -0.724731], [0.331299, -1.349243, -0.890121, -0.178589, -0.285721, 0.809875, -2.012329, -0.157227], [0.278946, -1.090057, -0.670441, -0.477539, -0.267105, 0.446045, -1.95668, 0.501343], [0.127304, -0.977112, -0.660324, -1.011658, -0.547409, 0.349182, -1.357574, 1.045654], [0.217728, -0.793182, -0.496262, -1.259949, -0.128937, 0.38855, -1.513306, 1.863647], [0.240143, -0.891541, -0.619995, -1.478577, -0.361481, 0.258362, -1.630585, 1.841064], [0.241547, -0.758453, -0.515442, -1.370605, -0.428238, 0.23996, -1.469406, 1.307617], [0.289948, -0.714661, -0.533798, -1.574036, 0.017929, -0.368317, -1.290283, 0.851563], [0.304916, -0.783752, -0.459915, -1.523621, -0.107651, -0.027649, -1.089905, 0.969238], [0.27179, -0.795593, -0.352432, -1.597656, -0.001678, -0.06189, -1.072495, 0.637329], [0.301956, -0.823578, -0.152115, -1.637634, 0.2034, -0.214508, -1.315491, 0.773071], [0.282486, -0.853271, -0.162094, -1.561096, 0.15686, -0.289307, -1.076874, 0.673706], [0.299881, -0.97052, -0.051086, -1.431152, -0.074692, -0.32428, -1.385452, 0.684326], [0.220886, -1.072266, -0.269531, -1.038269, 0.140533, -0.711273, -1.7453, 1.090332], [0.177628, -1.229126, -0.274292, -0.943481, 0.483246, -1.214447, -2.026321, 0.719971], [0.176987, -1.137543, -0.007645, -0.794861, 0.965118, -1.084717, -2.37677, 0.598267], [0.135727, -1.36795, 0.09462, -0.776367, 0.946655, -1.157959, -2.794403, 0.226074], [0.067337, -1.648987, 0.535721, -0.665833, 1.506119, -1.348755, -3.092728, 0.281616], [-0.038101, -1.437347, 0.983917, -0.280762, 1.880722, -1.351318, -3.002258, -0.599609], [-0.152573, -1.146027, 0.717545, -0.60321, 2.126541, -0.59198, -2.282028, -1.048584], [-0.113525, -0.629669, 0.925323, 0.465393, 2.368698, -0.352661, -1.969391, -0.915161], [-0.140121, -0.311951, 0.884262, 0.809021, 1.557693, -0.552429, -1.776062, -0.925537], [-0.189423, -0.117767, 0.975174, 1.595032, 1.284485, -0.698639, -2.007202, -1.307251], [-0.048874, -0.176941, 0.820679, 1.306519, 0.584259, -0.913147, -0.658066, -0.630981], [-0.127594, 0.33313, 0.791336, 1.400696, 0.685577, -1.500275, -0.657959, -0.207642], [-0.044128, 0.653351, 0.615326, 0.476685, 1.099625, -0.902893, -0.154449, 0.325073], [-0.150223, 1.059845, 1.208405, -0.038635, 0.758667, 0.458038, -0.178909, -0.998657], [-0.099854, 1.127197, 0.789871, -0.013611, 0.452805, 0.736176, 0.948273, -0.236328], [-0.250275, 1.188568, 0.935989, 0.34314, 0.130463, 0.879913, 1.669037, 0.12793], [-0.122818, 1.441223, 0.670029, 0.389526, -0.15274, 1.293549, 1.22908, -1.132568]]
#this one doesn't
reference = [[-0.453598, -2.439209, 0.973587, 1.362091, -0.073654, -1.755112, 1.090057, 4.246765], [-0.448502, -2.621201, 0.723282, 1.257324, 0.26619, -1.375351, 1.328735, 4.46991], [-0.481247, -2.29718, 0.612854, 1.078033, 0.309708, -2.037506, 1.056305, 3.181702], [-0.42482, -2.306702, 0.436157, 1.529907, 0.50708, -1.930069, 0.653198, 3.561768], [-0.39032, -2.361343, 0.589294, 1.965607, 0.611801, -2.417084, 0.035675, 3.381104], [-0.233444, -2.281525, 0.703171, 2.17868, 0.519257, -2.474442, -0.502808, 3.569153], [-0.174652, -1.924591, 0.180267, 2.127075, 0.250626, -2.208527, -0.396591, 2.565552], [-0.121078, -1.53801, 0.234344, 2.221039, 0.845367, -1.516205, -0.174149, 1.298645], [-0.18631, -1.047806, 0.629654, 2.073303, 0.775024, -1.931076, 0.382706, 2.278442], [-0.160477, -0.78743, 0.694214, 1.917572, 0.834885, -1.574707, 0.780045, 2.370422], [-0.203659, -0.427246, 0.726486, 1.548767, 0.465698, -1.185379, 0.555206, 2.619629], [-0.208298, -0.393707, 0.771881, 1.646484, 0.612946, -0.996277, 0.658539, 2.499146], [-0.180679, -0.166656, 0.689209, 1.205994, 0.3918, -1.051483, 0.771072, 1.854553], [-0.1978, 0.082764, 0.723541, 1.019104, 0.165405, -0.127533, 1.0522, 0.552368], [-0.171127, 0.168533, 0.529541, 0.584839, 0.702011, -0.36525, 0.711792, 1.029114], [-0.224243, 0.38765, 0.916031, 0.45108, 0.708923, -0.059326, 1.016312, 0.437561], [-0.217072, -0.981766, 1.67363, 1.864014, 0.050812, -2.572815, -0.22937, 0.757996], [-0.284714, -0.784927, 1.720383, 1.782379, -0.093414, -2.492111, 0.623398, 0.629028], [-0.261169, -0.427979, 1.680038, 1.585358, 0.067093, -1.8181, 1.276291, 0.838989], [-0.183075, -0.08197, 1.094147, 1.120392, -0.117752, -0.86142, 1.94194, 0.966858], [-0.188919, 0.121521, 1.277664, 0.90979, 0.114288, -0.880875, 1.920517, 0.95752], [-0.226868, 0.338455, 0.78067, 0.803009, 0.347092, -0.387955, 0.641296, 0.374634], [-0.206329, 0.768158, 0.759537, 0.264099, 0.15979, 0.152618, 0.911636, -0.011597], [-0.230453, 0.495941, 0.547165, 0.137604, 0.36377, 0.594406, 1.168839, 0.125916], [0.340851, -0.382736, -1.060455, -0.267792, 1.1306, 0.595047, -1.544922, -1.6828], [0.341492, -0.325836, -1.07164, -0.215607, 0.895645, 0.400177, -0.773956, -1.827515], [0.392075, -0.305389, -0.885422, -0.293427, 0.993225, 0.66655, -1.061218, -1.730713], [0.30191, -0.339005, -0.877853, 0.153992, 0.986588, 0.711823, -1.100525, -1.648376], [0.303574, -0.491241, -1.000183, 0.075378, 0.686295, 0.752792, -1.192123, -1.744568], [0.315781, -0.629456, -0.996063, 0.224731, 1.074173, 0.757736, -1.170807, -2.08313], [0.313675, -0.804688, -1.00325, 0.431641, 0.685883, 0.538879, -0.988373, -2.421326], [0.267181, -0.790329, -0.726974, 0.853027, 1.369629, -0.213638, -1.708023, -1.977844], [0.304459, -0.935257, -0.778061, 1.042633, 1.391861, -0.296768, -1.562164, -2.014099], [0.169754, -0.792953, -0.481842, 1.404236, 0.766983, -0.29805, -1.587265, -1.25531], [0.15918, -0.9814, -0.197662, 1.748718, 0.888367, -0.880234, -1.64949, -1.359802], [0.028244, -0.772934, -0.186172, 1.594238, 0.863571, -1.224701, -1.153183, -0.292664], [-0.020401, -0.461578, 0.368088, 1.000366, 1.079636, -0.389603, -0.144409, 0.651733], [0.018555, -0.725418, 0.632599, 1.707336, 0.535049, -1.783859, -0.916122, 1.557007], [-0.038971, -0.797668, 0.820419, 1.483093, 0.350494, -1.465073, -0.786453, 1.370361], [-0.244888, -0.469513, 1.067978, 1.028809, 0.4879, -1.796585, -0.77887, 1.888977], [-0.260193, -0.226593, 1.141754, 1.21228, 0.214005, -1.200943, -0.441177, 0.532715], [-0.165283, 0.016129, 1.263016, 0.745514, -0.211288, -0.802368, 0.215698, 0.316406], [-0.353134, 0.053787, 1.544189, 0.21106, -0.469086, -0.485367, 0.767761, 0.849548], [-0.330215, 0.162704, 1.570053, 0.304718, -0.561172, -0.410294, 0.895126, 0.858093], [-0.333847, 0.173904, 1.56958, 0.075531, -0.5569, -0.259552, 1.276764, 0.749084], [-0.347107, 0.206665, 1.389832, 0.50473, -0.721664, -0.56955, 1.542618, 0.817444], [-0.299057, 0.140244, 1.402924, 0.215363, -0.62767, -0.550461, 1.60788, 0.506958], [-0.292084, 0.052063, 1.463348, 0.290497, -0.462875, -0.497452, 1.280609, 0.261841], [-0.279877, 0.183548, 1.308609, 0.305756, -0.6483, -0.374771, 1.647781, 0.161865], [-0.28389, 0.27916, 1.148636, 0.466736, -0.724442, -0.21991, 1.819901, -0.218872], [-0.275528, 0.309753, 1.192856, 0.398163, -0.828781, -0.268066, 1.763672, 0.116089], [-0.275284, 0.160019, 1.200623, 0.718628, -0.925552, -0.026596, 1.367447, 0.174866], [-0.302795, 0.383438, 1.10556, 0.441833, -0.968323, -0.137375, 1.851791, 0.357971], [-0.317078, 0.22876, 1.272217, 0.462219, -0.855789, -0.294296, 1.593994, 0.127502], [-0.304932, 0.207718, 1.156189, 0.481506, -0.866776, -0.340027, 1.670105, 0.657837], [-0.257217, 0.155655, 1.041428, 0.717926, -0.761597, -0.17244, 1.114151, 0.653503], [-0.321426, 0.292358, 0.73848, 0.422607, -0.850754, -0.057907, 1.462357, 0.697754], [-0.34642, 0.361526, 0.69722, 0.585175, -0.464508, -0.26651, 1.860596, 0.106201], [-0.339844, 0.584229, 0.542603, 0.184937, -0.341263, 0.085648, 1.837311, 0.160461], [-0.32338, 0.661224, 0.512833, 0.319702, -0.195572, 0.004028, 1.046799, 0.233704], [-0.346329, 0.572388, 0.385986, 0.118988, 0.057556, 0.039001, 1.255081, -0.18573], [-0.383392, 0.558395, 0.553391, -0.358612, 0.443573, -0.086014, 0.652878, 0.829956], [-0.420395, 0.668991, 0.64856, -0.021271, 0.511475, 0.639221, 0.860474, 0.463196], [-0.359039, 0.748672, 0.522964, -0.308899, 0.717194, 0.218811, 0.681396, 0.606812], [-0.323914, 0.942627, 0.249069, -0.418365, 0.673599, 0.797974, 0.162674, 0.120361], [-0.411301, 0.92775, 0.493332, -0.286346, 0.165054, 0.63446, 1.085571, 0.120789], [-0.346191, 0.632309, 0.635056, -0.402496, 0.143814, 0.785614, 0.952164, 0.482727], [-0.203812, 0.789261, 0.240433, -0.47699, -0.12912, 0.91832, 1.145493, 0.052002], [-0.048203, 0.632095, 0.009583, -0.53833, 0.232727, 1.293045, 0.308151, 0.188904], [-0.062393, 0.732315, 0.06694, -0.697144, 0.126221, 0.864578, 0.581635, -0.088379]]
query = [[-0.113144, -3.316223, -1.101563, -2.128418, 1.853867, 3.61972, 1.218185, 1.71228], [-0.128952, -3.37915, -1.152237, -2.033081, 1.860199, 4.008179, 0.445938, 1.665894], [-0.0392, -2.976654, -0.888245, -1.613953, 1.638641, 3.849518, 0.034073, 0.768188], [-0.146042, -2.980713, -1.044113, -1.44397, 0.954514, 3.20929, -0.232422, 1.050781], [-0.155029, -2.997192, -1.064438, -1.369873, 0.67688, 2.570709, -0.855347, 1.523438], [-0.102341, -2.686401, -1.029648, -1.00531, 0.950089, 1.933228, -0.526367, 1.598633], [-0.060272, -2.538727, -1.278259, -0.65332, 0.630875, 1.459717, -0.264038, 1.872925], [0.064087, -2.592682, -1.112823, -0.775024, 0.848618, 0.810883, 0.298965, 2.312134], [0.111557, -2.815277, -1.203506, -1.173584, 0.54863, 0.46756, -0.023071, 3.029053], [0.266068, -2.624786, -1.089066, -0.864136, 0.055389, 0.619446, -0.160965, 2.928589], [0.181488, -2.31073, -1.307785, -0.720276, 0.001297, 0.534668, 0.495499, 2.989502], [0.216202, -2.25354, -1.288193, -0.902039, -0.152283, -0.060791, 0.566315, 2.911621], [0.430084, -2.0289, -1.099594, -1.091736, -0.302505, -0.087799, 0.955963, 2.677002], [0.484253, -1.412842, -0.881882, -1.087158, -1.064072, -0.145935, 1.437683, 2.606567], [0.339081, -1.277222, -1.24498, -1.048279, -0.219498, 0.448517, 1.168625, 0.563843], [0.105728, 0.138275, -1.01413, -0.489868, 1.319275, 1.604645, 1.634003, -0.94812], [-0.209061, 1.025665, 0.180405, 0.955566, 1.527405, 0.91745, 1.951233, -0.40686], [-0.136993, 1.332275, 0.639862, 1.277832, 1.277313, 0.361267, 0.390717, -0.728394], [-0.217758, 1.416718, 1.080002, 0.816101, 0.343933, -0.154175, 1.10347, -0.568848]]
reference = np.array( reference )
query = np.array( query )
rpy2.robjects.numpy2ri.activate()
# Set up our R namespaces
R = rpy2.robjects.r
rNull = R("NULL")
rprint = rpy2.robjects.globalenv.get("print")
rplot = rpy2.robjects.r('plot')
distConstr = rpy2.robjects.r('proxy::dist')
DTW = importr('dtw')
stepName = "asymmetricP05"
stepPattern = rpy2.robjects.r( stepName )
canDist = distConstr( reference, query, "Euclidean" ) #
alignment = R.dtw(canDist, rNull, "Euclidean", stepPattern, "none", True, False, True, False )
For some series the script doesn't generate the error but there are some which do. See the commented lines for examples. It is worth noting that for the classic constraint this error does not appear. I am thinking that perhaps I have not set-up something correct but I am no expert in python nor in R so that is why I was hoping that others who have used the R DTW can help me on this. I am sorry for the long lines for reference and query (the data is from outputting the MFCC's of a 2 second wav file).
One of the two series is too short to be compatible with the fancy step pattern you chose. Use the common symmetric2 pattern, which does not restrict slopes, before the more exotic ones.

Categories

Resources