问:
How to interpolate 3d using pythons griddata
I have ascii-Data in a file called 'Testdata_interpolate.csv' in the following manner

```<code>x,y,z,v
val11,val12,val13,val14
val21,val22,val23,val24
...
</code>```

Where x,y,z are representing coordinates and v a scalar value at this point in space. x,y,z are randomly distributed.

For further calculations v shall be interpolated as V onto a regular grid (X,Y,Z). Therefor I tried to use Phytons griddata in that code:

```<code>from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from scipy.interpolate import griddata as gd

#read values
f=open('Testdata_interpolate.csv','r')
headers = ["x","y","z","v"]
data = pd.read_csv(f, delimiter = ",",header=1,names=headers)
x=data.x
y=data.y
z=data.z
v=data.v

#generate new grid
X,Y,Z=np.mgrid[0:1:10j, 0:1:10j, 0:1:10j]

#interpolate "data.v" on new grid "inter_mesh"
V = gd((x,y,z), v, (X,Y,Z), method='nearest')

#Plot values
fig = plt.figure()
ax=fig.gca(projection='3d')
sc=ax.scatter(X, Y, Z, c=V, cmap=plt.hot())
plt.colorbar(sc)
plt.show()
</code>```

Trying this leads to the error.

```<code>ValueError: Buffer has wrong number of dimensions (expected 1, got 3)
</code>```

Because of that failure i tried to generate the new grid with

```<code>X=np.linspace(0,1,10)
Y=np.linspace(0,1,10)
Z=np.linspace(0,1,10)
</code>```

Using this notation performs the interpolation but I have only a straight line of (correctly) interpolated values  from one corner of the volume to the other.

What should be the correct generation of the X,Y,Z-grid to interpolate on?

EDIT1:
I have found a work around, that works for me. The generation of the new grid X,Y,Z is done with this code:

```<code>xi,yi,zi=np.ogrid[0:1:10j, 0:1:10j, 0:1:20j]
X1=xi.reshape(xi.shape[0],)
Y1=yi.reshape(yi.shape[1],)
Z1=zi.reshape(zi.shape[2],)
ar_len=len(X1)*len(Y1)*len(Z1)+1
X=np.arange(ar_len,dtype=float)
Y=np.arange(ar_len,dtype=float)
Z=np.arange(ar_len,dtype=float)
l=0
for i in range(0,len(X1)):
    for j in range(0,len(Y1)):
        for k in range(0,len(Z1)):
            l=l+1
            X[l]=X1[i]
            Y[l]=Y1[j]
            Z[l]=Z1[k]
</code>```

Does someone know if this could be simplified and/or how to write in a good python-style?

答:
Here is the complete solution:

```<code>from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from scipy.interpolate import griddata as gd
import time

#read values
print("Read original data...")
start_time=time.clock()
f=open('Daten.csv','r')
headers = ["x","y","z","V"]
data = pd.read_csv(f, delimiter = ",",header=1,names=headers)
x=data.x
y=data.y
z=data.z
v=data.V
print ('time needed: ', time.clock()-start_time, ' seconds')
print("")

#generate new grid X,Y,Z
print("Generate new grid...")
start_time=time.clock()
xi,yi,zi=np.ogrid[0:1:11j, 0:1:11j, 0:1:11j]
X1=xi.reshape(xi.shape[0],)
Y1=yi.reshape(yi.shape[1],)
Z1=zi.reshape(zi.shape[2],)
ar_len=len(X1)*len(Y1)*len(Z1)
X=np.arange(ar_len,dtype=float)
Y=np.arange(ar_len,dtype=float)
Z=np.arange(ar_len,dtype=float)
l=0
for i in range(0,len(X1)):
    for j in range(0,len(Y1)):
        for k in range(0,len(Z1)):
            X[l]=X1[i]
            Y[l]=Y1[j]
            Z[l]=Z1[k]
            l=l+1
print ('time needed: ', time.clock()-start_time, ' seconds')
print("")

#interpolate "data.v" on new grid "X,Y,Z"
print("Interpolate...")
start_time=time.clock()
V = gd((x,y,z), v, (X,Y,Z), method='linear')
print ('time needed: ', time.clock()-start_time, ' seconds')
print("")

#Plot original values
fig1 = plt.figure()
ax1=fig1.gca(projection='3d')
sc1=ax1.scatter(x, y, z, c=v, cmap=plt.hot())
plt.colorbar(sc1)
ax1.set_xlabel('X')
ax1.set_ylabel('Y')
ax1.set_zlabel('Z')

#Plot interpolated values
fig2 = plt.figure()
ax2=fig2.gca(projection='3d')
sc2=ax2.scatter(X, Y, Z, c=V, cmap=plt.hot())
plt.colorbar(sc2)
ax2.set_xlabel('X')
ax2.set_ylabel('Y')
ax2.set_zlabel('Z')

#Show plots
plt.show()
</code>```

Example data are calculated with random points

```<code>def func(x,y,z):
    return 0.5*(3)**(1/2)-((x-0.5)**2+(y-0.5)**2+(z-0.5)**2)**(1/2)
x = np.random.rand(10)
y = np.random.rand(10)
z = np.random.rand(10)
v = func(x,y,z)
</code>```

resulting in this example data:

```x,y,z,v
0.6306633776,0.5399341613,0.0223922509,0.3692590427
0.6201798089,0.713310769,0.2586306574,0.5222175648
0.0133608796,0.5962421199,0.1336130457,0.2493248448
0.625635438,0.2813785867,0.1412831986,0.4275538206
0.4478070925,0.2533920221,0.8647321435,0.4226642295
0.9496287584,0.5412782144,0.0181683893,0.2056985056
0.353725578,0.8192529518,0.9945807043,0.2594541163
0.6531066992,0.7549814415,0.8023866946,0.441885203
0.2034177743,0.7157782351,0.5439790104,0.4966266806
0.3936962193,0.5198892568,0.2851481802,0.6254897914
0.7136407618,0.6884816985,0.6673836339,0.5355938576
0.2679115187,0.1078689156,0.0960926992,0.2571141146
0.9544471861,0.304474494,0.791678864,0.2917179703
0.2513473134,0.8128617403,0.0276061489,0.2472632705
0.5621786268,0.0105501017,0.3463567749,0.3492724404
0.0236232636,0.7537357578,0.0049020726,0.1336057239
0.5544935236,0.3265725226,0.4704909401,0.6818585809
0.9169167232,0.1903847884,0.0384998546,0.1712855118
0.6509500724,0.3350786431,0.4485415479,0.6366066805
0.4892437129,0.4890809474,0.8062363257,0.5594057524
0.2930552054,0.0103116581,0.5241043581,0.3338582869
0.956388208,0.4938978335,0.6916433722,0.3709954906
0.0722823141,0.0776713405,0.0164990656,0.094613018
0.3340717987,0.1857906293,0.8615063092,0.3591264906
0.9461038462,0.4192224785,0.1804858052,0.311387711
0.6194368915,0.7870312196,0.1767282374,0.4175204154
0.2598983985,0.0137079303,0.5218954065,0.3232472126
0.1628694471,0.3909106815,0.4686704314,0.5103021533
0.405955568,0.7681639045,0.5503229067,0.5774277084
0.2701853069,0.2277688606,0.8209407311,0.3865178029
0.8193266613,0.5615418105,0.7331885243,0.4658581901
0.0428746114,0.5050042546,0.402704194,0.3986335582
0.3438295609,0.7730675675,0.9674056518,0.3026222215
0.9552899428,0.2841943004,0.072097092,0.2049944433
0.3554257909,0.4985691797,0.5750067732,0.7031458004
0.7771471706,0.9535270029,0.804036098,0.2537058423
0.6300111088,0.673049493,0.9747896229,0.344226399
0.0862787074,0.2732020325,0.2496220012,0.331898295
0.4397787892,0.8737769038,0.5699767084,0.4810156535
0.9463236536,0.1280889919,0.8617868226,0.1816188677
0.0510125536,0.8540123724,0.1709006799,0.2063127017
0.2290255208,0.4523648438,0.0913191637,0.3733629408
0.3739807131,0.5281513263,0.1555660222,0.4981828792
0.381137688,0.3792761887,0.6625859691,0.6312133829
0.45184571,0.3788999769,0.0564337434,0.4037104947
0.9339652646,0.1587308487,0.284979922,0.2735525196
0.3656675596,0.0956345971,0.5860244642,0.431333798
0.3683657888,0.1729067734,0.6504682948,0.4826740608
0.2295411313,0.4762862368,0.6254150038,0.5669614216
0.7909070767,0.3906802474,0.8597905841,0.3906024342
0.5232714652,0.4474381413,0.9464774509,0.4158627396
0.5506931653,0.0136374333,0.4617536616,0.3755347049
0.6163667089,0.4232951417,0.0508881645,0.3957847346
0.2410430499,0.2445243536,0.8316876458,0.3737417434
0.4896791476,0.4842978234,0.7950337037,0.5703939361
0.6027538624,0.6198397316,0.5598951721,0.6971842087
0.9190498489,0.3987407853,0.0112006215,0.214273122
0.3530254834,0.520464629,0.0603594208,0.4020166232
0.009953508,0.9841304369,0.5740347477,0.1731985942
0.2196149815,0.1010876149,0.9944747656,0.1715816383
0.671561366,0.6656832779,0.0124795495,0.3232911773
0.9913571495,0.4012237578,0.6751740861,0.3351068085
0.2136069964,0.2133224305,0.8533352507,0.3283909734
0.9030364749,0.3387038174,0.8082359016,0.3336118149
0.1987606561,0.4216349495,0.7621533491,0.4590725787
0.5490367836,0.5750362376,0.5902005466,0.7388594425
0.83009432,0.3577592844,0.7607350977,0.4219787031
0.6959727876,0.7086074705,0.8989627659,0.3750124723
0.3955585478,0.9522785004,0.3537629556,0.3793539211
0.1740074199,0.90613637,0.5406577303,0.3436548798
0.862232854,0.1641101963,0.0871443357,0.2222207748
0.5892735408,0.028922464,0.4544688624,0.3844063692
0.2092728323,0.5754606259,0.5228441169,0.5647971751
0.6361810902,0.0517793576,0.8129563089,0.3026528052
0.8755833265,0.0690054237,0.4029022524,0.2861572011
0.3604205895,0.7272419375,0.6232588424,0.5722328712
0.7245441675,0.8508843923,0.1043419443,0.2914949546
0.378985798,0.705913034,0.3252829289,0.5701019853
0.2450076354,0.4675920206,0.7503598065,0.5072059285
0.3954747342,0.7524948808,0.538161918,0.5900987324
0.8431238907,0.89791946,0.2850646916,0.2983361509
0.0075750139,0.2701604665,0.9613816069,0.1531568568
0.3915120547,0.5508184589,0.6184136179,0.6975797599
0.7743560073,0.7732019407,0.7936674234,0.3800716254
0.5731431141,0.0463964108,0.1102689808,0.2635335793
0.3454076014,0.7799256704,0.4952835517,0.5462138412
0.3992618618,0.039215973,0.1443308299,0.2752880251
0.7309012385,0.7477130298,0.308651145,0.4770633087
0.8798876626,0.0781818882,0.5140124665,0.2981860736
0.6337635873,0.7414852159,0.5548462313,0.5845721823
0.8779629321,0.7226434117,0.0649765363,0.2482297412
0.3596338067,0.1629595478,0.9852069955,0.2587982938
0.1470704943,0.7341692382,0.3173635881,0.4047765262
0.5495922826,0.5831609034,0.4090942864,0.7332135854
0.8372890817,0.6471977771,0.5592359801,0.4932788256
0.8986365935,0.6013925502,0.3293837716,0.4207148601
0.7529078043,0.7790015346,0.3484371136,0.4600998905
0.5088906595,0.0117897109,0.9908112199,0.1736931253
0.3322010292,0.8568216281,0.5259938139,0.4708623397
0.0764332382,0.9636281886,0.1978059367,0.1691171237
0.3475818783,0.3942058018,0.8030983983,0.5106490747
0.6377423069,0.8868203075,0.3145786878,0.4154879953
0.0045190767,0.8130553286,0.5093343537,0.2798580946
0.7140381144,0.7407960293,0.027507628,0.2941477212
0.3959185294,0.8889921485,0.7900283924,0.3697751519
0.6414700936,0.0623275826,0.3796580266,0.3905749616
0.4647447769,0.5080850862,0.2602779063,0.6235898833
0.9261314441,0.9800868873,0.2389269791,0.1730387161
0.4068127254,0.8521595996,0.0881227537,0.3161680425
0.6252986387,0.1626255445,0.8149288615,0.3877979894
0.0148919826,0.4288521749,0.5650029395,0.371437511
0.6999084446,0.5193721698,0.6204045802,0.6318546752
0.1939084605,0.4495516764,0.2238104075,0.4506728368
0.6700975735,0.5135514273,0.8026774478,0.5185625092
0.901180391,0.0469020734,0.9142602429,0.1326394304
0.0953740531,0.8537873632,0.9959291318,0.1347023842
0.4603053633,0.7629654546,0.8185415223,0.4510613138
0.657618954,0.7520074762,0.1866926524,0.4341538988
0.36567682,0.744729749,0.7568356825,0.4866839553
0.061796768,0.4784516747,0.6231214956,0.4103442592
0.0582960593,0.7570687738,0.3419325419,0.3310748949
0.56401618,0.7113661579,0.2757130117,0.5512582246
0.3284323403,0.7378651794,0.6241919629,0.5475305858
0.4275464981,0.3531682925,0.5295711182,0.6996417769
0.9765874392,0.742617911,0.4658176337,0.3301453126
0.072844224,0.7883095643,0.9160671954,0.2036838205
0.804863217,0.3942617685,0.7601831764,0.4515167308
0.007844326,0.474396331,0.7450142246,0.3156575944
0.2441903849,0.9658714967,0.1156812242,0.2101475706
0.8654428603,0.810985844,0.7199050951,0.338181743
0.4064994813,0.7387058858,0.1379702581,0.4224170394
0.9703619592,0.2396814054,0.3980043184,0.3188423792
0.72785583,0.7091076345,0.5463329126,0.5533098448
0.4026269424,0.0984237189,0.6391085789,0.4300251531
0.7936799405,0.5424635891,0.5265214701,0.5681085493
0.4642213171,0.1198021551,0.9364229437,0.2861154959
0.4620715394,0.6806879169,0.4046251749,0.6582200893
0.6011675165,0.7123237968,0.3787300339,0.6014074419
0.7100177282,0.8298857084,0.4942637179,0.474918089
0.7301135939,0.7515287406,0.5509963591,0.5213232105
0.6994698314,0.3896948785,0.3934400219,0.6144097
0.4389661969,0.690571303,0.8227801091,0.4862497522
0.4713839427,0.9078846897,0.3451963795,0.4288149742
0.6821897594,0.3855670615,0.7383466417,0.5449379897
0.1437000915,0.1926245144,0.6224994888,0.3797791301
0.6098303414,0.5698709236,0.9622570089,0.3857898448
0.2782655851,0.8486976961,0.4988174602,0.4527970984
0.2702581113,0.2774259285,0.836997639,0.4013879522
0.6564572272,0.0922870446,0.1510823881,0.3070511487
0.2726379978,0.8572610917,0.1478971792,0.3152937412
0.5602773549,0.1056130207,0.4101895268,0.4570750766
0.4259546883,0.3321364383,0.8096145661,0.5061336658
0.530420481,0.5331294727,0.3407970744,0.7005910085
0.1333708394,0.2706074738,0.9213914799,0.262197074
0.3853847516,0.7872972615,0.5643746353,0.5500816346
0.6383190772,0.3975758359,0.6680134941,0.6255022018
0.3074904762,0.1474470852,0.8589877068,0.3272994548
0.164294517,0.4569216795,0.2065183679,0.418046184
0.3177061073,0.5843665436,0.646404561,0.6174633944
0.6420002836,0.3850971295,0.7164241147,0.5828185048
0.2020011383,0.7824059389,0.6739242807,0.4201486368
0.1840347406,0.0619099449,0.1514663014,0.2231936368
0.9046038843,0.7000077552,0.715691632,0.3657951714
0.1403577243,0.1693091849,0.804109877,0.2905414345
0.3889402016,0.7763260252,0.9926312481,0.2903728197
0.3241593493,0.882831795,0.7627518547,0.3695189538
0.7666204442,0.1088284545,0.602145248,0.3817369659
0.8106734194,0.5358877461,0.3051675919,0.4975616049
0.930311342,0.4840485226,0.5832080611,0.4274528532
0.987676861,0.2516205517,0.9622990862,0.1496166405
0.21015611,0.4693912954,0.2686613362,0.4939179586
0.6057100715,0.9904309815,0.3821192914,0.3506682187
0.6056677665,0.9920663947,0.9869230643,0.1657475416
0.1820842028,0.2265129565,0.334319282,0.4151199621
0.8876163042,0.1416437103,0.8254844324,0.2458595023
0.6232990447,0.5307597364,0.7508213738,0.584848987
0.7259092082,0.3400181764,0.0396656887,0.328869158
0.112385463,0.2929171231,0.7552510665,0.3578114192
0.5559131078,0.487973381,0.5951903189,0.754975361
0.7368538344,0.03127444,0.4817180756,0.3405374228
0.8190162682,0.1239617304,0.3222973147,0.3418551987
0.97988197,0.2996560477,0.1457110446,0.2367837425
0.38865937,0.2980691287,0.5831884996,0.6208863837
0.7511422474,0.7001080603,0.5557206437,0.5401106076
0.6946423471,0.6442451245,0.6779334003,0.5654383213
0.6962270452,0.838215151,0.7650459673,0.3936443009
0.4959681755,0.183628186,0.1338019599,0.3820745954
0.1016190418,0.1526950048,0.5857433221,0.3306002785
0.5497103268,0.1446169499,0.2261669635,0.4146355935
0.5969970797,0.8211549471,0.6187163732,0.5101567331
0.8423643133,0.7705178764,0.7524700778,0.3619079724
0.1934005817,0.8919879179,0.3949489795,0.3574062457
0.1128752324,0.2121278716,0.6453188962,0.3621866106
0.984939352,0.4026293467,0.02108349,0.1775428384
0.0369142757,0.2954519021,0.9591341697,0.182583747
0.694564745,0.2295872361,0.7298591792,0.4612862963
0.9867100492,0.6877417272,0.720915026,0.2995123176
0.3844537931,0.6819663068,0.5866166998,0.6337214748
0.5320925768,0.1904548845,0.0721293763,0.3369494332
0.3250763989,0.8926740442,0.7442687657,0.3715980571
0.0884456354,0.9474986999,0.9294405386,0.121679209
0.2715253571,0.1475996259,0.3489222973,0.4196946314
0.6080823056,0.1631524074,0.5568934452,0.5077169479
0.9537259699,0.777563684,0.588825372,0.3267677648
0.6059857589,0.105086105,0.9913446577,0.2267996704
0.9239502157,0.3577242379,0.805413884,0.3244962555
0.2808765186,0.4074664948,0.6179072143,0.6005453464
0.3651996099,0.4394979137,0.4216764531,0.6987943492
0.3838798791,0.2186392358,0.1964127432,0.4361265964
0.6355936999,0.2846375207,0.3993498098,0.5923520405
0.9409695841,0.5761777789,0.8722091025,0.2839628263
0.5727240253,0.5160758496,0.6947885946,0.6574832896
0.3439960505,0.532515792,0.9814805574,0.3588587289
0.844665446,0.0352556573,0.9347137247,0.1423144144
0.2812371739,0.2012480763,0.0445996914,0.2790847534
0.8722510531,0.4501423568,0.8145664254,0.3761186095
0.5294358074,0.8459800522,0.3094731357,0.4699583017
0.9270235896,0.6212266353,0.2540890089,0.3585638203
0.3562878568,0.3831062196,0.3007920287,0.5939938765
0.9597124545,0.7427999057,0.3312525342,0.3194331954
0.5537447884,0.4097215465,0.7437895008,0.6005597334
0.7381427777,0.1960822498,0.650809103,0.4515119939
0.3400718119,0.4290469985,0.2536068172,0.5638318329
0.7990917316,0.0754560353,0.6559687782,0.3237895679
0.0624729146,0.5030904655,0.6033139733,0.4164552996
0.4639588027,0.4688854972,0.3431048342,0.7020645144
0.9235925954,0.6130429817,0.5084196649,0.4275276349
0.1875197874,0.9535069139,0.6924070234,0.2826448532
0.6484220238,0.0996337414,0.4432496125,0.4352785585
0.7373545477,0.9727624131,0.0764032472,0.1883265846
0.4487495478,0.2451071694,0.7262175529,0.5213932156
0.7541094572,0.9352042695,0.1495581423,0.252198174
0.7621058298,0.450101799,0.4171894081,0.5866566678
0.9890595462,0.102434163,0.7846070734,0.1744771259
0.8505146717,0.5804425551,0.2416315574,0.4232096499
0.698750175,0.874646647,0.775899879,0.3600782866
0.5626629528,0.4913736361,0.8220569456,0.5378155075
0.2800742853,0.2206115442,0.7681508234,0.4206827343
0.7407627309,0.863310113,0.494226838,0.4301420934
0.4423902395,0.9326594783,0.859696349,0.3004331724
0.5643581424,0.5599856473,0.2547866842,0.6055070385
0.2382607802,0.616935845,0.2136456727,0.4608338295
0.3724339716,0.5628447905,0.3013413771,0.6217145204
0.9782979445,0.352440188,0.7066606615,0.3244984416
0.9116224624,0.6685323042,0.0067169218,0.2018233378
0.4626697185,0.7594809555,0.8075250707,0.4619269191
0.6385735262,0.0212779644,0.1778529548,0.2725979624
0.3206460142,0.9822497766,0.8319778354,0.2537003411
0.6585250726,0.4610784496,0.7516457304,0.5660743088
0.8514618205,0.0135934496,0.2031696615,0.1965293296
0.6645740872,0.3285068459,0.8808723508,0.417072979
0.7205516925,0.2825607097,0.0957799255,0.3567938625
0.3957547375,0.8866808113,0.4711353827,0.4645004472
0.0271670725,0.3897163997,0.1214067018,0.2503417714
0.1681776842,0.9795156751,0.869546556,0.1756588425
0.2989788846,0.0882321439,0.436671313,0.4034534865
0.840025475,0.2751567103,0.8797768454,0.3088878257
0.4927941296,0.9276139628,0.7721402462,0.3591073243
0.0218443484,0.8739084165,0.7930522648,0.1919927926
0.7082019283,0.8781607534,0.8841319197,0.2881751376
0.4281279931,0.1301428349,0.4840983904,0.4889143205
0.0969747704,0.864892806,0.0574357833,0.1649981707
0.5002240002,0.4913999372,0.0605066316,0.4264478428
0.9010480595,0.2705834925,0.2748491089,0.3520561404
0.0521717295,0.0697361203,0.303329303,0.2145988699
0.2311421199,0.6535710409,0.3484011026,0.5212778875
0.6018243214,0.5142935712,0.461814318,0.7563411072
0.0399977568,0.5296795048,0.5360999634,0.4036552662
0.7723277332,0.5261161379,0.9881150654,0.3064713277
0.6994159547,0.8103932027,0.5725178612,0.4900340429
0.3287358341,0.1474853975,0.5576576959,0.4698911218
0.1405604806,0.7350755552,0.0638994106,0.2539461533
0.6212150408,0.0984797311,0.5947549054,0.4360369103
0.8115583443,0.9193747561,0.2263494512,0.276255609
0.8576836871,0.360387413,0.7281182796,0.4194078448
0.2520324121,0.7656230663,0.5065125659,0.5025890937
0.7081140195,0.5198283888,0.9897978333,0.3334781969
0.2835104092,0.0506739943,0.8162458521,0.2754553052
0.0245973891,0.4038492943,0.5152942104,0.3807558771
0.1753831567,0.5730637948,0.5916852657,0.5208868794
0.1361253039,0.5642410712,0.142771754,0.3520762531
0.8370623511,0.9539091442,0.9245005246,0.1590280664
0.8552911956,0.5826776285,0.2288357087,0.4114954303
0.0116507787,0.8178670548,0.5500240563,0.2811948021
0.3930195158,0.0708319199,0.6882616921,0.3853253625
0.1332551293,0.8507888781,0.4804438921,0.3581503419
0.2441977277,0.9069888443,0.9289183899,0.2217849928
0.8054478295,0.5513038328,0.0952561504,0.3563705759
0.7313680745,0.171937156,0.0195727289,0.2399529013
0.3302117368,0.6714438749,0.0725409359,0.3751666582
0.5449309083,0.5529359679,0.3449625086,0.6961500761
0.6124853263,0.1790586073,0.1321548123,0.3650599276
0.1443241257,0.8709559835,0.7982253207,0.271843604
0.7459991787,0.5998450893,0.8482665855,0.4281050316
0.8584817678,0.6925073438,0.7560070771,0.3852885955
0.2597912861,0.6662350075,0.1327351142,0.3967517093
0.3500584369,0.6450641899,0.2351119224,0.5288432791
0.7772057197,0.7863756281,0.370178006,0.4468503073
0.5231376264,0.3559675029,0.7235375114,0.5990989552
0.677049257,0.4865385675,0.234308279,0.5464636098
0.4092060379,0.3541481854,0.2136098231,0.532055901
0.6233284474,0.0708858047,0.1600539615,0.3048550129
0.6995308912,0.3063223441,0.0161737235,0.3079828635
0.0258335667,0.647618864,0.9748796014,0.178904038
0.2664170874,0.9572557646,0.5082773798,0.352496119
0.8055430382,0.1183620434,0.3749769024,0.3614118358
0.4322677506,0.2703249249,0.2001609637,0.4823044825
0.9676376693,0.9059139411,0.8382212095,0.160444293
0.8322898693,0.0185976884,0.4761012045,0.2805889039
0.2948531147,0.3478730215,0.2177719094,0.4853936168
0.0765675294,0.8864499313,0.8564301572,0.1909838765
0.0242837934,0.3447383349,0.2180677066,0.2916580023
0.3916847831,0.5498005105,0.278363295,0.6143607339
0.1209140326,0.904015694,0.8785706784,0.1950182427
0.095376816,0.9004315941,0.4104590563,0.2897590043
0.8886550217,0.9244852912,0.8212411644,0.2069075281
0.5141279931,0.7926382609,0.5584593244,0.5672709151
0.0450283497,0.1014355833,0.8525325127,0.1659311463
0.2976476999,0.3824220433,0.6514629608,0.5872565789
0.5382730589,0.3876561896,0.7850114383,0.5572901147
0.9883794178,0.6267332823,0.1704153952,0.2633631498
0.2727107098,0.4992260081,0.3652242266,0.6017801965
0.5885485657,0.6286556898,0.7184304553,0.5975016641
0.8075339779,0.6204837612,0.7815521859,0.4320148997
0.55606677,0.9956735406,0.8111887951,0.278084754
0.0738468201,0.3396072187,0.9644173832,0.2156286919
0.5701443475,0.0310006478,0.2060800641,0.3081100423
0.1462757623,0.9983125547,0.4322945414,0.2511918754
0.8209407749,0.2872603394,0.6165387833,0.4637289557
0.9700720356,0.6198606657,0.4466772395,0.3779909637
0.0672598168,0.7865218778,0.9365435464,0.1878446605
0.3451940787,0.9115880754,0.819826649,0.3222803326
0.046568463,0.8108580533,0.2672551173,0.2690303716
0.3043736313,0.1478831825,0.935546138,0.2727662971
0.4933483334,0.0429575489,0.7964345364,0.3212268345
0.9717623311,0.1613696611,0.4953735107,0.2852917231
0.944890823,0.3716735151,0.5037043622,0.4029819356
0.0074656803,0.7508402078,0.0299907815,0.140477658
0.0895123173,0.6329249935,0.277553003,0.3805855434
0.4782147665,0.5600381009,0.1571106566,0.5172385466
0.7425196474,0.280470928,0.0512009144,0.3106611881
0.6553517027,0.8474713349,0.7578740204,0.4062760258
0.8096713415,0.7807511792,0.1521645495,0.3222358627
0.6701439515,0.5897307442,0.2443192509,0.5460672562
0.1621262084,0.2350032294,0.3728480548,0.4181977532
0.397112443,0.5021985798,0.8988902758,0.4540737862
0.7518828503,0.206660689,0.9419525069,0.2788159522
0.2356205091,0.2507433102,0.4474492101,0.4988919156
0.6384330828,0.5935726465,0.2625215861,0.5756539939
0.2229873218,0.873685293,0.8071468128,0.308606453
0.2435969377,0.6235657639,0.8793150751,0.3917987127
0.5902711594,0.9281412953,0.6057317526,0.4158775898
0.9269695207,0.8969441284,0.5875941348,0.2764998784
0.3155099158,0.3245774735,0.8951628866,0.3959580033
0.2609362076,0.8569220916,0.6559534561,0.4090064143
0.0307727377,0.1355391456,0.6812289128,0.2448572648
0.4932484023,0.8158363269,0.8927346144,0.3620029372
0.537291864,0.5096903368,0.3889371785,0.7484688809
0.8171296908,0.9548852438,0.2046223387,0.2377421965
0.9415802566,0.2354928628,0.4819942187,0.3509706913
0.1402832662,0.892427227,0.2708303237,0.2864445228
0.5193751879,0.2108712015,0.9383615667,0.3405430319
0.0795427464,0.9951977585,0.3791774532,0.2052658333
0.6176248324,0.5187001912,0.8249672042,0.5199199543
0.1677473273,0.7299368383,0.1314358704,0.3191229392
0.62029663,0.6693051737,0.9226033295,0.3951442137
0.9429850334,0.0301803869,0.182328794,0.1463857692
0.1574578131,0.7652385918,0.7141439618,0.3827611937
0.9022531854,0.7319792568,0.5622911152,0.3975148022
0.5484219011,0.7850542005,0.5698941148,0.5685598343
0.9690821893,0.1918015403,0.4621056385,0.3034772961
0.9680029444,0.6161592897,0.485864774,0.3836152659
0.4546147305,0.945019161,0.1045665224,0.2689747262
0.2027256479,0.1298824021,0.2959831648,0.3493224468
0.6926069361,0.8676264975,0.5454309694,0.4485201386
0.1146755546,0.8939644142,0.6506296446,0.2947354794
0.0528997749,0.1493129965,0.881090304,0.1818398986
0.0052914657,0.8885298115,0.8198042133,0.1603578594
0.0202115708,0.4421242778,0.5370242392,0.3813426929
0.1849038715,0.5112594456,0.6441010017,0.5193592185
0.0805469996,0.5838084337,0.9182785681,0.2677598828
0.7693425801,0.820612936,0.442239741,0.4433265421
0.7578899088,0.7314517664,0.9861302383,0.2690331644
0.1508395098,0.6000181628,0.7830312685,0.4055654384
0.5401503961,0.0364483602,0.7337838814,0.3453075528
0.0436407762,0.9630885066,0.1376225652,0.1216920703
0.444924719,0.8353369719,0.7270109649,0.4573468633
0.1167792308,0.3903460717,0.1642017505,0.3448319596
0.9810069531,0.6506951952,0.4515428573,0.3596413346
0.8784186119,0.2383881681,0.490021029,0.4058721943
0.5645867137,0.9274879948,0.0210813162,0.2208273451
0.3946540737,0.9695610544,0.488660959,0.384658681
0.271317021,0.1212995985,0.2448700111,0.3553384055
0.786645854,0.2630994225,0.9100719727,0.3124490748
0.8299039428,0.8205378493,0.2270603696,0.3311635841
0.7050802828,0.5059673086,0.6061498964,0.6350246859
0.7437824024,0.8692702649,0.9084872927,0.2638192459
0.845273826,0.5778816518,0.1422795477,0.3627923676
0.6983100581,0.9155369166,0.8378064328,0.2949641162
0.5051642517,0.9934110959,0.5252557582,0.37194137
0.8364283272,0.3347889184,0.6477939289,0.4631336488
0.4695722678,0.8685884955,0.5668372237,0.4901922754
0.8835673289,0.7960490172,0.9573795091,0.1997184687
0.3635725794,0.6287233307,0.575452674,0.6638491367
0.6857467318,0.8007785211,0.0313382315,0.2789875682
0.9980463693,0.8996167057,0.7536597216,0.1789395636
0.8942417091,0.1993275521,0.600034287,0.3602217811
0.7709446424,0.9467620606,0.4151530892,0.3366802079
0.4111202505,0.2465459624,0.657798339,0.5545147702
0.0067004252,0.4699943093,0.7930665149,0.2914535684
0.7817791928,0.1694443643,0.4205176247,0.4244554889
0.6459198485,0.9738754274,0.8656608967,0.2499422809
0.8327427604,0.4241890884,0.136178942,0.3671959729
0.534428725,0.2622625089,0.5599898174,0.6184305129
0.9989386221,0.9057762275,0.6974975633,0.1932703347
0.1933982413,0.1050110651,0.5889336976,0.3581572125
0.9823128266,0.2797887572,0.1843159252,0.2489556434
0.4904733788,0.5546334197,0.5523404245,0.7897686854
0.7477880857,0.0203964258,0.9589280666,0.1574821841
0.9252310984,0.4871681698,0.0893520095,0.2747404344
0.0526026997,0.9218705003,0.4097528197,0.2445082143
0.9077590647,0.4944113583,0.7820557189,0.3701886198
0.8695934701,0.690935508,0.3343188402,0.4182464985
0.9608450404,0.0235156625,0.3931224881,0.1945804859
0.4544547639,0.1954265567,0.8639801924,0.389243555
0.3445517028,0.9521310535,0.0215255675,0.1896198707
0.1814975096,0.2379880835,0.4335933037,0.4482887282
0.0892784427,0.3839917327,0.1986442627,0.3435644999
0.6653460559,0.8407859359,0.8169383144,0.3721385063
0.2203435269,0.9656928381,0.3485150414,0.3020881244
0.8790159578,0.4066135207,0.6334525648,0.4534921108
0.4351909137,0.7973373982,0.0702711394,0.3394547631
0.4351811069,0.1131372598,0.3432317074,0.4436031432
0.0732657426,0.3757036198,0.50024382,0.4215574342
0.644406111,0.7858667555,0.5250004492,0.5447810276
0.756305656,0.1980193351,0.1795031028,0.3565127225
0.8996659567,0.4597209891,0.7638623497,0.3854230575
0.6825881271,0.7367330294,0.6621422887,0.5259209005
0.3012990604,0.3476373241,0.792477446,0.4810065668
0.0865565365,0.3004642099,0.8129682083,0.3104184128
0.0421286432,0.6892087005,0.385207029,0.3574749757
0.4616250802,0.9213045978,0.9162832329,0.2725088256
0.02303428,0.6399530106,0.2572940856,0.3128624042
0.8347259695,0.8056977472,0.6998366233,0.3706192438
0.138024968,0.3405246541,0.0675626993,0.2799705183
0.8304352884,0.1141640784,0.7441919012,0.3023885324
0.9077913961,0.8236495343,0.8436371752,0.2422230697
0.724509081,0.0846541386,0.091546439,0.2417251367
0.1206736149,0.0897049186,0.758703451,0.2502673054
0.3937018856,0.2676819996,0.5028267012,0.6105279817
0.4960492478,0.3324569377,0.4629601291,0.6943913798
0.7832525712,0.7736390004,0.6018076366,0.459239076
0.3967061569,0.2262678901,0.0954549723,0.3667703934
0.0428036742,0.4119245463,0.9250495513,0.2355867573
0.4063226071,0.6730445873,0.8238667281,0.4870669091
0.5567263441,0.8210499264,0.2593653657,0.4608143963
0.5592416906,0.9012447973,0.0700987189,0.2749906528
0.6384119732,0.6510454672,0.3042892856,0.5826964585
0.9798633371,0.5523820339,0.5814304271,0.376491325
0.9628448317,0.7487761635,0.5941262873,0.3321952101
0.3706260702,0.252344383,0.7096924064,0.5166805546
0.218632948,0.994277475,0.7809678472,0.2316591283
0.3168673543,0.0835500112,0.2528727206,0.348299558
0.7906319198,0.2219688163,0.723273431,0.4060044512
0.1247621915,0.1237534864,0.525949755,0.3340120188
0.9565921184,0.3952253068,0.8622134365,0.2738660735
0.505859251,0.4401271036,0.7924990443,0.5674039286
0.3055876407,0.3310139194,0.9801331168,0.3211581991
0.6631613025,0.276597142,0.5381954648,0.586759686
0.1150634772,0.9736670898,0.2515394538,0.2070342949
0.8232522632,0.4894588125,0.8950760974,0.3554489991
0.4975627763,0.5231172818,0.4102074437,0.7732727653
0.6119855439,0.1610955916,0.4975586061,0.5090899468
0.682962104,0.0776563653,0.419031434,0.3986869975
0.6726203319,0.7876597129,0.9536890857,0.3017739741
0.0913773174,0.9450365906,0.7027720889,0.2287290962
0.602766628,0.7837863102,0.8969436441,0.3673672982
0.6155271592,0.9020927012,0.2874681981,0.3967761824
0.8478364911,0.5960036262,0.5907624708,0.4939437637
0.246004391,0.3808873582,0.0403679333,0.3275430665
0.4305861098,0.0345780167,0.2477172503,0.3320942318
0.5289812609,0.0837675568,0.7474209829,0.3809413873
0.9523989413,0.4010429585,0.1831988612,0.304936944
0.114349951,0.133078384,0.5551008282,0.3308679187
```

Producing following results:

original values at random points
interpolated values using griddata with linear interpolation

Body:
I have ascii-Data in a file called 'Testdata_interpolate.csv' in the following manner

x,y,z,v
val11,val12,val13,val14
val21,val22,val23,val24
...

Where x,y,z are representing coordinates and v a scalar value at this point in space. x,y,z are randomly distributed.

For further calculations v shall be interpolated as V onto a regular grid (X,Y,Z). Therefor I tried to use Phytons griddata in that code:

from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from scipy.interpolate import griddata as gd

#read values
f=open('Testdata_interpolate.csv','r')
headers = ["x","y","z","v"]
data = pd.read_csv(f, delimiter = ",",header=1,names=headers)
x=data.x
y=data.y
z=data.z
v=data.v

#generate new grid
X,Y,Z=np.mgrid[0:1:10j, 0:1:10j, 0:1:10j]

#interpolate "data.v" on new grid "inter_mesh"
V = gd((x,y,z), v, (X,Y,Z), method='nearest')

#Plot values
fig = plt.figure()
ax=fig.gca(projection='3d')
sc=ax.scatter(X, Y, Z, c=V, cmap=plt.hot())
plt.colorbar(sc)
plt.show()

Trying this leads to the error.

ValueError: Buffer has wrong number of dimensions (expected 1, got 3)

Because of that failure i tried to generate the new grid with

X=np.linspace(0,1,10)
Y=np.linspace(0,1,10)
Z=np.linspace(0,1,10)

Using this notation performs the interpolation but I have only a straight line of (correctly) interpolated values  from one corner of the volume to the other.

What should be the correct generation of the X,Y,Z-grid to interpolate on?

EDIT1:
I have found a work around, that works for me. The generation of the new grid X,Y,Z is done with this code:

xi,yi,zi=np.ogrid[0:1:10j, 0:1:10j, 0:1:20j]
X1=xi.reshape(xi.shape[0],)
Y1=yi.reshape(yi.shape[1],)
Z1=zi.reshape(zi.shape[2],)
ar_len=len(X1)*len(Y1)*len(Z1)+1
X=np.arange(ar_len,dtype=float)
Y=np.arange(ar_len,dtype=float)
Z=np.arange(ar_len,dtype=float)
l=0
for i in range(0,len(X1)):
    for j in range(0,len(Y1)):
        for k in range(0,len(Z1)):
            l=l+1
            X[l]=X1[i]
            Y[l]=Y1[j]
            Z[l]=Z1[k]

Does someone know if this could be simplified and/or how to write in a good python-style?

Body:
Here is the complete solution:

from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from scipy.interpolate import griddata as gd
import time

#read values
print("Read original data...")
start_time=time.clock()
f=open('Daten.csv','r')
headers = ["x","y","z","V"]
data = pd.read_csv(f, delimiter = ",",header=1,names=headers)
x=data.x
y=data.y
z=data.z
v=data.V
print ('time needed: ', time.clock()-start_time, ' seconds')
print("")

#generate new grid X,Y,Z
print("Generate new grid...")
start_time=time.clock()
xi,yi,zi=np.ogrid[0:1:11j, 0:1:11j, 0:1:11j]
X1=xi.reshape(xi.shape[0],)
Y1=yi.reshape(yi.shape[1],)
Z1=zi.reshape(zi.shape[2],)
ar_len=len(X1)*len(Y1)*len(Z1)
X=np.arange(ar_len,dtype=float)
Y=np.arange(ar_len,dtype=float)
Z=np.arange(ar_len,dtype=float)
l=0
for i in range(0,len(X1)):
    for j in range(0,len(Y1)):
        for k in range(0,len(Z1)):
            X[l]=X1[i]
            Y[l]=Y1[j]
            Z[l]=Z1[k]
            l=l+1
print ('time needed: ', time.clock()-start_time, ' seconds')
print("")

#interpolate "data.v" on new grid "X,Y,Z"
print("Interpolate...")
start_time=time.clock()
V = gd((x,y,z), v, (X,Y,Z), method='linear')
print ('time needed: ', time.clock()-start_time, ' seconds')
print("")

#Plot original values
fig1 = plt.figure()
ax1=fig1.gca(projection='3d')
sc1=ax1.scatter(x, y, z, c=v, cmap=plt.hot())
plt.colorbar(sc1)
ax1.set_xlabel('X')
ax1.set_ylabel('Y')
ax1.set_zlabel('Z')

#Plot interpolated values
fig2 = plt.figure()
ax2=fig2.gca(projection='3d')
sc2=ax2.scatter(X, Y, Z, c=V, cmap=plt.hot())
plt.colorbar(sc2)
ax2.set_xlabel('X')
ax2.set_ylabel('Y')
ax2.set_zlabel('Z')

#Show plots
plt.show()

Example data are calculated with random points

def func(x,y,z):
    return 0.5*(3)**(1/2)-((x-0.5)**2+(y-0.5)**2+(z-0.5)**2)**(1/2)
x = np.random.rand(10)
y = np.random.rand(10)
z = np.random.rand(10)
v = func(x,y,z)

resulting in this example data:

x,y,z,v
0.6306633776,0.5399341613,0.0223922509,0.3692590427
0.6201798089,0.713310769,0.2586306574,0.5222175648
0.0133608796,0.5962421199,0.1336130457,0.2493248448
0.625635438,0.2813785867,0.1412831986,0.4275538206
0.4478070925,0.2533920221,0.8647321435,0.4226642295
0.9496287584,0.5412782144,0.0181683893,0.2056985056
0.353725578,0.8192529518,0.9945807043,0.2594541163
0.6531066992,0.7549814415,0.8023866946,0.441885203
0.2034177743,0.7157782351,0.5439790104,0.4966266806
0.3936962193,0.5198892568,0.2851481802,0.6254897914
0.7136407618,0.6884816985,0.6673836339,0.5355938576
0.2679115187,0.1078689156,0.0960926992,0.2571141146
0.9544471861,0.304474494,0.791678864,0.2917179703
0.2513473134,0.8128617403,0.0276061489,0.2472632705
0.5621786268,0.0105501017,0.3463567749,0.3492724404
0.0236232636,0.7537357578,0.0049020726,0.1336057239
0.5544935236,0.3265725226,0.4704909401,0.6818585809
0.9169167232,0.1903847884,0.0384998546,0.1712855118
0.6509500724,0.3350786431,0.4485415479,0.6366066805
0.4892437129,0.4890809474,0.8062363257,0.5594057524
0.2930552054,0.0103116581,0.5241043581,0.3338582869
0.956388208,0.4938978335,0.6916433722,0.3709954906
0.0722823141,0.0776713405,0.0164990656,0.094613018
0.3340717987,0.1857906293,0.8615063092,0.3591264906
0.9461038462,0.4192224785,0.1804858052,0.311387711
0.6194368915,0.7870312196,0.1767282374,0.4175204154
0.2598983985,0.0137079303,0.5218954065,0.3232472126
0.1628694471,0.3909106815,0.4686704314,0.5103021533
0.405955568,0.7681639045,0.5503229067,0.5774277084
0.2701853069,0.2277688606,0.8209407311,0.3865178029
0.8193266613,0.5615418105,0.7331885243,0.4658581901
0.0428746114,0.5050042546,0.402704194,0.3986335582
0.3438295609,0.7730675675,0.9674056518,0.3026222215
0.9552899428,0.2841943004,0.072097092,0.2049944433
0.3554257909,0.4985691797,0.5750067732,0.7031458004
0.7771471706,0.9535270029,0.804036098,0.2537058423
0.6300111088,0.673049493,0.9747896229,0.344226399
0.0862787074,0.2732020325,0.2496220012,0.331898295
0.4397787892,0.8737769038,0.5699767084,0.4810156535
0.9463236536,0.1280889919,0.8617868226,0.1816188677
0.0510125536,0.8540123724,0.1709006799,0.2063127017
0.2290255208,0.4523648438,0.0913191637,0.3733629408
0.3739807131,0.5281513263,0.1555660222,0.4981828792
0.381137688,0.3792761887,0.6625859691,0.6312133829
0.45184571,0.3788999769,0.0564337434,0.4037104947
0.9339652646,0.1587308487,0.284979922,0.2735525196
0.3656675596,0.0956345971,0.5860244642,0.431333798
0.3683657888,0.1729067734,0.6504682948,0.4826740608
0.2295411313,0.4762862368,0.6254150038,0.5669614216
0.7909070767,0.3906802474,0.8597905841,0.3906024342
0.5232714652,0.4474381413,0.9464774509,0.4158627396
0.5506931653,0.0136374333,0.4617536616,0.3755347049
0.6163667089,0.4232951417,0.0508881645,0.3957847346
0.2410430499,0.2445243536,0.8316876458,0.3737417434
0.4896791476,0.4842978234,0.7950337037,0.5703939361
0.6027538624,0.6198397316,0.5598951721,0.6971842087
0.9190498489,0.3987407853,0.0112006215,0.214273122
0.3530254834,0.520464629,0.0603594208,0.4020166232
0.009953508,0.9841304369,0.5740347477,0.1731985942
0.2196149815,0.1010876149,0.9944747656,0.1715816383
0.671561366,0.6656832779,0.0124795495,0.3232911773
0.9913571495,0.4012237578,0.6751740861,0.3351068085
0.2136069964,0.2133224305,0.8533352507,0.3283909734
0.9030364749,0.3387038174,0.8082359016,0.3336118149
0.1987606561,0.4216349495,0.7621533491,0.4590725787
0.5490367836,0.5750362376,0.5902005466,0.7388594425
0.83009432,0.3577592844,0.7607350977,0.4219787031
0.6959727876,0.7086074705,0.8989627659,0.3750124723
0.3955585478,0.9522785004,0.3537629556,0.3793539211
0.1740074199,0.90613637,0.5406577303,0.3436548798
0.862232854,0.1641101963,0.0871443357,0.2222207748
0.5892735408,0.028922464,0.4544688624,0.3844063692
0.2092728323,0.5754606259,0.5228441169,0.5647971751
0.6361810902,0.0517793576,0.8129563089,0.3026528052
0.8755833265,0.0690054237,0.4029022524,0.2861572011
0.3604205895,0.7272419375,0.6232588424,0.5722328712
0.7245441675,0.8508843923,0.1043419443,0.2914949546
0.378985798,0.705913034,0.3252829289,0.5701019853
0.2450076354,0.4675920206,0.7503598065,0.5072059285
0.3954747342,0.7524948808,0.538161918,0.5900987324
0.8431238907,0.89791946,0.2850646916,0.2983361509
0.0075750139,0.2701604665,0.9613816069,0.1531568568
0.3915120547,0.5508184589,0.6184136179,0.6975797599
0.7743560073,0.7732019407,0.7936674234,0.3800716254
0.5731431141,0.0463964108,0.1102689808,0.2635335793
0.3454076014,0.7799256704,0.4952835517,0.5462138412
0.3992618618,0.039215973,0.1443308299,0.2752880251
0.7309012385,0.7477130298,0.308651145,0.4770633087
0.8798876626,0.0781818882,0.5140124665,0.2981860736
0.6337635873,0.7414852159,0.5548462313,0.5845721823
0.8779629321,0.7226434117,0.0649765363,0.2482297412
0.3596338067,0.1629595478,0.9852069955,0.2587982938
0.1470704943,0.7341692382,0.3173635881,0.4047765262
0.5495922826,0.5831609034,0.4090942864,0.7332135854
0.8372890817,0.6471977771,0.5592359801,0.4932788256
0.8986365935,0.6013925502,0.3293837716,0.4207148601
0.7529078043,0.7790015346,0.3484371136,0.4600998905
0.5088906595,0.0117897109,0.9908112199,0.1736931253
0.3322010292,0.8568216281,0.5259938139,0.4708623397
0.0764332382,0.9636281886,0.1978059367,0.1691171237
0.3475818783,0.3942058018,0.8030983983,0.5106490747
0.6377423069,0.8868203075,0.3145786878,0.4154879953
0.0045190767,0.8130553286,0.5093343537,0.2798580946
0.7140381144,0.7407960293,0.027507628,0.2941477212
0.3959185294,0.8889921485,0.7900283924,0.3697751519
0.6414700936,0.0623275826,0.3796580266,0.3905749616
0.4647447769,0.5080850862,0.2602779063,0.6235898833
0.9261314441,0.9800868873,0.2389269791,0.1730387161
0.4068127254,0.8521595996,0.0881227537,0.3161680425
0.6252986387,0.1626255445,0.8149288615,0.3877979894
0.0148919826,0.4288521749,0.5650029395,0.371437511
0.6999084446,0.5193721698,0.6204045802,0.6318546752
0.1939084605,0.4495516764,0.2238104075,0.4506728368
0.6700975735,0.5135514273,0.8026774478,0.5185625092
0.901180391,0.0469020734,0.9142602429,0.1326394304
0.0953740531,0.8537873632,0.9959291318,0.1347023842
0.4603053633,0.7629654546,0.8185415223,0.4510613138
0.657618954,0.7520074762,0.1866926524,0.4341538988
0.36567682,0.744729749,0.7568356825,0.4866839553
0.061796768,0.4784516747,0.6231214956,0.4103442592
0.0582960593,0.7570687738,0.3419325419,0.3310748949
0.56401618,0.7113661579,0.2757130117,0.5512582246
0.3284323403,0.7378651794,0.6241919629,0.5475305858
0.4275464981,0.3531682925,0.5295711182,0.6996417769
0.9765874392,0.742617911,0.4658176337,0.3301453126
0.072844224,0.7883095643,0.9160671954,0.2036838205
0.804863217,0.3942617685,0.7601831764,0.4515167308
0.007844326,0.474396331,0.7450142246,0.3156575944
0.2441903849,0.9658714967,0.1156812242,0.2101475706
0.8654428603,0.810985844,0.7199050951,0.338181743
0.4064994813,0.7387058858,0.1379702581,0.4224170394
0.9703619592,0.2396814054,0.3980043184,0.3188423792
0.72785583,0.7091076345,0.5463329126,0.5533098448
0.4026269424,0.0984237189,0.6391085789,0.4300251531
0.7936799405,0.5424635891,0.5265214701,0.5681085493
0.4642213171,0.1198021551,0.9364229437,0.2861154959
0.4620715394,0.6806879169,0.4046251749,0.6582200893
0.6011675165,0.7123237968,0.3787300339,0.6014074419
0.7100177282,0.8298857084,0.4942637179,0.474918089
0.7301135939,0.7515287406,0.5509963591,0.5213232105
0.6994698314,0.3896948785,0.3934400219,0.6144097
0.4389661969,0.690571303,0.8227801091,0.4862497522
0.4713839427,0.9078846897,0.3451963795,0.4288149742
0.6821897594,0.3855670615,0.7383466417,0.5449379897
0.1437000915,0.1926245144,0.6224994888,0.3797791301
0.6098303414,0.5698709236,0.9622570089,0.3857898448
0.2782655851,0.8486976961,0.4988174602,0.4527970984
0.2702581113,0.2774259285,0.836997639,0.4013879522
0.6564572272,0.0922870446,0.1510823881,0.3070511487
0.2726379978,0.8572610917,0.1478971792,0.3152937412
0.5602773549,0.1056130207,0.4101895268,0.4570750766
0.4259546883,0.3321364383,0.8096145661,0.5061336658
0.530420481,0.5331294727,0.3407970744,0.7005910085
0.1333708394,0.2706074738,0.9213914799,0.262197074
0.3853847516,0.7872972615,0.5643746353,0.5500816346
0.6383190772,0.3975758359,0.6680134941,0.6255022018
0.3074904762,0.1474470852,0.8589877068,0.3272994548
0.164294517,0.4569216795,0.2065183679,0.418046184
0.3177061073,0.5843665436,0.646404561,0.6174633944
0.6420002836,0.3850971295,0.7164241147,0.5828185048
0.2020011383,0.7824059389,0.6739242807,0.4201486368
0.1840347406,0.0619099449,0.1514663014,0.2231936368
0.9046038843,0.7000077552,0.715691632,0.3657951714
0.1403577243,0.1693091849,0.804109877,0.2905414345
0.3889402016,0.7763260252,0.9926312481,0.2903728197
0.3241593493,0.882831795,0.7627518547,0.3695189538
0.7666204442,0.1088284545,0.602145248,0.3817369659
0.8106734194,0.5358877461,0.3051675919,0.4975616049
0.930311342,0.4840485226,0.5832080611,0.4274528532
0.987676861,0.2516205517,0.9622990862,0.1496166405
0.21015611,0.4693912954,0.2686613362,0.4939179586
0.6057100715,0.9904309815,0.3821192914,0.3506682187
0.6056677665,0.9920663947,0.9869230643,0.1657475416
0.1820842028,0.2265129565,0.334319282,0.4151199621
0.8876163042,0.1416437103,0.8254844324,0.2458595023
0.6232990447,0.5307597364,0.7508213738,0.584848987
0.7259092082,0.3400181764,0.0396656887,0.328869158
0.112385463,0.2929171231,0.7552510665,0.3578114192
0.5559131078,0.487973381,0.5951903189,0.754975361
0.7368538344,0.03127444,0.4817180756,0.3405374228
0.8190162682,0.1239617304,0.3222973147,0.3418551987
0.97988197,0.2996560477,0.1457110446,0.2367837425
0.38865937,0.2980691287,0.5831884996,0.6208863837
0.7511422474,0.7001080603,0.5557206437,0.5401106076
0.6946423471,0.6442451245,0.6779334003,0.5654383213
0.6962270452,0.838215151,0.7650459673,0.3936443009
0.4959681755,0.183628186,0.1338019599,0.3820745954
0.1016190418,0.1526950048,0.5857433221,0.3306002785
0.5497103268,0.1446169499,0.2261669635,0.4146355935
0.5969970797,0.8211549471,0.6187163732,0.5101567331
0.8423643133,0.7705178764,0.7524700778,0.3619079724
0.1934005817,0.8919879179,0.3949489795,0.3574062457
0.1128752324,0.2121278716,0.6453188962,0.3621866106
0.984939352,0.4026293467,0.02108349,0.1775428384
0.0369142757,0.2954519021,0.9591341697,0.182583747
0.694564745,0.2295872361,0.7298591792,0.4612862963
0.9867100492,0.6877417272,0.720915026,0.2995123176
0.3844537931,0.6819663068,0.5866166998,0.6337214748
0.5320925768,0.1904548845,0.0721293763,0.3369494332
0.3250763989,0.8926740442,0.7442687657,0.3715980571
0.0884456354,0.9474986999,0.9294405386,0.121679209
0.2715253571,0.1475996259,0.3489222973,0.4196946314
0.6080823056,0.1631524074,0.5568934452,0.5077169479
0.9537259699,0.777563684,0.588825372,0.3267677648
0.6059857589,0.105086105,0.9913446577,0.2267996704
0.9239502157,0.3577242379,0.805413884,0.3244962555
0.2808765186,0.4074664948,0.6179072143,0.6005453464
0.3651996099,0.4394979137,0.4216764531,0.6987943492
0.3838798791,0.2186392358,0.1964127432,0.4361265964
0.6355936999,0.2846375207,0.3993498098,0.5923520405
0.9409695841,0.5761777789,0.8722091025,0.2839628263
0.5727240253,0.5160758496,0.6947885946,0.6574832896
0.3439960505,0.532515792,0.9814805574,0.3588587289
0.844665446,0.0352556573,0.9347137247,0.1423144144
0.2812371739,0.2012480763,0.0445996914,0.2790847534
0.8722510531,0.4501423568,0.8145664254,0.3761186095
0.5294358074,0.8459800522,0.3094731357,0.4699583017
0.9270235896,0.6212266353,0.2540890089,0.3585638203
0.3562878568,0.3831062196,0.3007920287,0.5939938765
0.9597124545,0.7427999057,0.3312525342,0.3194331954
0.5537447884,0.4097215465,0.7437895008,0.6005597334
0.7381427777,0.1960822498,0.650809103,0.4515119939
0.3400718119,0.4290469985,0.2536068172,0.5638318329
0.7990917316,0.0754560353,0.6559687782,0.3237895679
0.0624729146,0.5030904655,0.6033139733,0.4164552996
0.4639588027,0.4688854972,0.3431048342,0.7020645144
0.9235925954,0.6130429817,0.5084196649,0.4275276349
0.1875197874,0.9535069139,0.6924070234,0.2826448532
0.6484220238,0.0996337414,0.4432496125,0.4352785585
0.7373545477,0.9727624131,0.0764032472,0.1883265846
0.4487495478,0.2451071694,0.7262175529,0.5213932156
0.7541094572,0.9352042695,0.1495581423,0.252198174
0.7621058298,0.450101799,0.4171894081,0.5866566678
0.9890595462,0.102434163,0.7846070734,0.1744771259
0.8505146717,0.5804425551,0.2416315574,0.4232096499
0.698750175,0.874646647,0.775899879,0.3600782866
0.5626629528,0.4913736361,0.8220569456,0.5378155075
0.2800742853,0.2206115442,0.7681508234,0.4206827343
0.7407627309,0.863310113,0.494226838,0.4301420934
0.4423902395,0.9326594783,0.859696349,0.3004331724
0.5643581424,0.5599856473,0.2547866842,0.6055070385
0.2382607802,0.616935845,0.2136456727,0.4608338295
0.3724339716,0.5628447905,0.3013413771,0.6217145204
0.9782979445,0.352440188,0.7066606615,0.3244984416
0.9116224624,0.6685323042,0.0067169218,0.2018233378
0.4626697185,0.7594809555,0.8075250707,0.4619269191
0.6385735262,0.0212779644,0.1778529548,0.2725979624
0.3206460142,0.9822497766,0.8319778354,0.2537003411
0.6585250726,0.4610784496,0.7516457304,0.5660743088
0.8514618205,0.0135934496,0.2031696615,0.1965293296
0.6645740872,0.3285068459,0.8808723508,0.417072979
0.7205516925,0.2825607097,0.0957799255,0.3567938625
0.3957547375,0.8866808113,0.4711353827,0.4645004472
0.0271670725,0.3897163997,0.1214067018,0.2503417714
0.1681776842,0.9795156751,0.869546556,0.1756588425
0.2989788846,0.0882321439,0.436671313,0.4034534865
0.840025475,0.2751567103,0.8797768454,0.3088878257
0.4927941296,0.9276139628,0.7721402462,0.3591073243
0.0218443484,0.8739084165,0.7930522648,0.1919927926
0.7082019283,0.8781607534,0.8841319197,0.2881751376
0.4281279931,0.1301428349,0.4840983904,0.4889143205
0.0969747704,0.864892806,0.0574357833,0.1649981707
0.5002240002,0.4913999372,0.0605066316,0.4264478428
0.9010480595,0.2705834925,0.2748491089,0.3520561404
0.0521717295,0.0697361203,0.303329303,0.2145988699
0.2311421199,0.6535710409,0.3484011026,0.5212778875
0.6018243214,0.5142935712,0.461814318,0.7563411072
0.0399977568,0.5296795048,0.5360999634,0.4036552662
0.7723277332,0.5261161379,0.9881150654,0.3064713277
0.6994159547,0.8103932027,0.5725178612,0.4900340429
0.3287358341,0.1474853975,0.5576576959,0.4698911218
0.1405604806,0.7350755552,0.0638994106,0.2539461533
0.6212150408,0.0984797311,0.5947549054,0.4360369103
0.8115583443,0.9193747561,0.2263494512,0.276255609
0.8576836871,0.360387413,0.7281182796,0.4194078448
0.2520324121,0.7656230663,0.5065125659,0.5025890937
0.7081140195,0.5198283888,0.9897978333,0.3334781969
0.2835104092,0.0506739943,0.8162458521,0.2754553052
0.0245973891,0.4038492943,0.5152942104,0.3807558771
0.1753831567,0.5730637948,0.5916852657,0.5208868794
0.1361253039,0.5642410712,0.142771754,0.3520762531
0.8370623511,0.9539091442,0.9245005246,0.1590280664
0.8552911956,0.5826776285,0.2288357087,0.4114954303
0.0116507787,0.8178670548,0.5500240563,0.2811948021
0.3930195158,0.0708319199,0.6882616921,0.3853253625
0.1332551293,0.8507888781,0.4804438921,0.3581503419
0.2441977277,0.9069888443,0.9289183899,0.2217849928
0.8054478295,0.5513038328,0.0952561504,0.3563705759
0.7313680745,0.171937156,0.0195727289,0.2399529013
0.3302117368,0.6714438749,0.0725409359,0.3751666582
0.5449309083,0.5529359679,0.3449625086,0.6961500761
0.6124853263,0.1790586073,0.1321548123,0.3650599276
0.1443241257,0.8709559835,0.7982253207,0.271843604
0.7459991787,0.5998450893,0.8482665855,0.4281050316
0.8584817678,0.6925073438,0.7560070771,0.3852885955
0.2597912861,0.6662350075,0.1327351142,0.3967517093
0.3500584369,0.6450641899,0.2351119224,0.5288432791
0.7772057197,0.7863756281,0.370178006,0.4468503073
0.5231376264,0.3559675029,0.7235375114,0.5990989552
0.677049257,0.4865385675,0.234308279,0.5464636098
0.4092060379,0.3541481854,0.2136098231,0.532055901
0.6233284474,0.0708858047,0.1600539615,0.3048550129
0.6995308912,0.3063223441,0.0161737235,0.3079828635
0.0258335667,0.647618864,0.9748796014,0.178904038
0.2664170874,0.9572557646,0.5082773798,0.352496119
0.8055430382,0.1183620434,0.3749769024,0.3614118358
0.4322677506,0.2703249249,0.2001609637,0.4823044825
0.9676376693,0.9059139411,0.8382212095,0.160444293
0.8322898693,0.0185976884,0.4761012045,0.2805889039
0.2948531147,0.3478730215,0.2177719094,0.4853936168
0.0765675294,0.8864499313,0.8564301572,0.1909838765
0.0242837934,0.3447383349,0.2180677066,0.2916580023
0.3916847831,0.5498005105,0.278363295,0.6143607339
0.1209140326,0.904015694,0.8785706784,0.1950182427
0.095376816,0.9004315941,0.4104590563,0.2897590043
0.8886550217,0.9244852912,0.8212411644,0.2069075281
0.5141279931,0.7926382609,0.5584593244,0.5672709151
0.0450283497,0.1014355833,0.8525325127,0.1659311463
0.2976476999,0.3824220433,0.6514629608,0.5872565789
0.5382730589,0.3876561896,0.7850114383,0.5572901147
0.9883794178,0.6267332823,0.1704153952,0.2633631498
0.2727107098,0.4992260081,0.3652242266,0.6017801965
0.5885485657,0.6286556898,0.7184304553,0.5975016641
0.8075339779,0.6204837612,0.7815521859,0.4320148997
0.55606677,0.9956735406,0.8111887951,0.278084754
0.0738468201,0.3396072187,0.9644173832,0.2156286919
0.5701443475,0.0310006478,0.2060800641,0.3081100423
0.1462757623,0.9983125547,0.4322945414,0.2511918754
0.8209407749,0.2872603394,0.6165387833,0.4637289557
0.9700720356,0.6198606657,0.4466772395,0.3779909637
0.0672598168,0.7865218778,0.9365435464,0.1878446605
0.3451940787,0.9115880754,0.819826649,0.3222803326
0.046568463,0.8108580533,0.2672551173,0.2690303716
0.3043736313,0.1478831825,0.935546138,0.2727662971
0.4933483334,0.0429575489,0.7964345364,0.3212268345
0.9717623311,0.1613696611,0.4953735107,0.2852917231
0.944890823,0.3716735151,0.5037043622,0.4029819356
0.0074656803,0.7508402078,0.0299907815,0.140477658
0.0895123173,0.6329249935,0.277553003,0.3805855434
0.4782147665,0.5600381009,0.1571106566,0.5172385466
0.7425196474,0.280470928,0.0512009144,0.3106611881
0.6553517027,0.8474713349,0.7578740204,0.4062760258
0.8096713415,0.7807511792,0.1521645495,0.3222358627
0.6701439515,0.5897307442,0.2443192509,0.5460672562
0.1621262084,0.2350032294,0.3728480548,0.4181977532
0.397112443,0.5021985798,0.8988902758,0.4540737862
0.7518828503,0.206660689,0.9419525069,0.2788159522
0.2356205091,0.2507433102,0.4474492101,0.4988919156
0.6384330828,0.5935726465,0.2625215861,0.5756539939
0.2229873218,0.873685293,0.8071468128,0.308606453
0.2435969377,0.6235657639,0.8793150751,0.3917987127
0.5902711594,0.9281412953,0.6057317526,0.4158775898
0.9269695207,0.8969441284,0.5875941348,0.2764998784
0.3155099158,0.3245774735,0.8951628866,0.3959580033
0.2609362076,0.8569220916,0.6559534561,0.4090064143
0.0307727377,0.1355391456,0.6812289128,0.2448572648
0.4932484023,0.8158363269,0.8927346144,0.3620029372
0.537291864,0.5096903368,0.3889371785,0.7484688809
0.8171296908,0.9548852438,0.2046223387,0.2377421965
0.9415802566,0.2354928628,0.4819942187,0.3509706913
0.1402832662,0.892427227,0.2708303237,0.2864445228
0.5193751879,0.2108712015,0.9383615667,0.3405430319
0.0795427464,0.9951977585,0.3791774532,0.2052658333
0.6176248324,0.5187001912,0.8249672042,0.5199199543
0.1677473273,0.7299368383,0.1314358704,0.3191229392
0.62029663,0.6693051737,0.9226033295,0.3951442137
0.9429850334,0.0301803869,0.182328794,0.1463857692
0.1574578131,0.7652385918,0.7141439618,0.3827611937
0.9022531854,0.7319792568,0.5622911152,0.3975148022
0.5484219011,0.7850542005,0.5698941148,0.5685598343
0.9690821893,0.1918015403,0.4621056385,0.3034772961
0.9680029444,0.6161592897,0.485864774,0.3836152659
0.4546147305,0.945019161,0.1045665224,0.2689747262
0.2027256479,0.1298824021,0.2959831648,0.3493224468
0.6926069361,0.8676264975,0.5454309694,0.4485201386
0.1146755546,0.8939644142,0.6506296446,0.2947354794
0.0528997749,0.1493129965,0.881090304,0.1818398986
0.0052914657,0.8885298115,0.8198042133,0.1603578594
0.0202115708,0.4421242778,0.5370242392,0.3813426929
0.1849038715,0.5112594456,0.6441010017,0.5193592185
0.0805469996,0.5838084337,0.9182785681,0.2677598828
0.7693425801,0.820612936,0.442239741,0.4433265421
0.7578899088,0.7314517664,0.9861302383,0.2690331644
0.1508395098,0.6000181628,0.7830312685,0.4055654384
0.5401503961,0.0364483602,0.7337838814,0.3453075528
0.0436407762,0.9630885066,0.1376225652,0.1216920703
0.444924719,0.8353369719,0.7270109649,0.4573468633
0.1167792308,0.3903460717,0.1642017505,0.3448319596
0.9810069531,0.6506951952,0.4515428573,0.3596413346
0.8784186119,0.2383881681,0.490021029,0.4058721943
0.5645867137,0.9274879948,0.0210813162,0.2208273451
0.3946540737,0.9695610544,0.488660959,0.384658681
0.271317021,0.1212995985,0.2448700111,0.3553384055
0.786645854,0.2630994225,0.9100719727,0.3124490748
0.8299039428,0.8205378493,0.2270603696,0.3311635841
0.7050802828,0.5059673086,0.6061498964,0.6350246859
0.7437824024,0.8692702649,0.9084872927,0.2638192459
0.845273826,0.5778816518,0.1422795477,0.3627923676
0.6983100581,0.9155369166,0.8378064328,0.2949641162
0.5051642517,0.9934110959,0.5252557582,0.37194137
0.8364283272,0.3347889184,0.6477939289,0.4631336488
0.4695722678,0.8685884955,0.5668372237,0.4901922754
0.8835673289,0.7960490172,0.9573795091,0.1997184687
0.3635725794,0.6287233307,0.575452674,0.6638491367
0.6857467318,0.8007785211,0.0313382315,0.2789875682
0.9980463693,0.8996167057,0.7536597216,0.1789395636
0.8942417091,0.1993275521,0.600034287,0.3602217811
0.7709446424,0.9467620606,0.4151530892,0.3366802079
0.4111202505,0.2465459624,0.657798339,0.5545147702
0.0067004252,0.4699943093,0.7930665149,0.2914535684
0.7817791928,0.1694443643,0.4205176247,0.4244554889
0.6459198485,0.9738754274,0.8656608967,0.2499422809
0.8327427604,0.4241890884,0.136178942,0.3671959729
0.534428725,0.2622625089,0.5599898174,0.6184305129
0.9989386221,0.9057762275,0.6974975633,0.1932703347
0.1933982413,0.1050110651,0.5889336976,0.3581572125
0.9823128266,0.2797887572,0.1843159252,0.2489556434
0.4904733788,0.5546334197,0.5523404245,0.7897686854
0.7477880857,0.0203964258,0.9589280666,0.1574821841
0.9252310984,0.4871681698,0.0893520095,0.2747404344
0.0526026997,0.9218705003,0.4097528197,0.2445082143
0.9077590647,0.4944113583,0.7820557189,0.3701886198
0.8695934701,0.690935508,0.3343188402,0.4182464985
0.9608450404,0.0235156625,0.3931224881,0.1945804859
0.4544547639,0.1954265567,0.8639801924,0.389243555
0.3445517028,0.9521310535,0.0215255675,0.1896198707
0.1814975096,0.2379880835,0.4335933037,0.4482887282
0.0892784427,0.3839917327,0.1986442627,0.3435644999
0.6653460559,0.8407859359,0.8169383144,0.3721385063
0.2203435269,0.9656928381,0.3485150414,0.3020881244
0.8790159578,0.4066135207,0.6334525648,0.4534921108
0.4351909137,0.7973373982,0.0702711394,0.3394547631
0.4351811069,0.1131372598,0.3432317074,0.4436031432
0.0732657426,0.3757036198,0.50024382,0.4215574342
0.644406111,0.7858667555,0.5250004492,0.5447810276
0.756305656,0.1980193351,0.1795031028,0.3565127225
0.8996659567,0.4597209891,0.7638623497,0.3854230575
0.6825881271,0.7367330294,0.6621422887,0.5259209005
0.3012990604,0.3476373241,0.792477446,0.4810065668
0.0865565365,0.3004642099,0.8129682083,0.3104184128
0.0421286432,0.6892087005,0.385207029,0.3574749757
0.4616250802,0.9213045978,0.9162832329,0.2725088256
0.02303428,0.6399530106,0.2572940856,0.3128624042
0.8347259695,0.8056977472,0.6998366233,0.3706192438
0.138024968,0.3405246541,0.0675626993,0.2799705183
0.8304352884,0.1141640784,0.7441919012,0.3023885324
0.9077913961,0.8236495343,0.8436371752,0.2422230697
0.724509081,0.0846541386,0.091546439,0.2417251367
0.1206736149,0.0897049186,0.758703451,0.2502673054
0.3937018856,0.2676819996,0.5028267012,0.6105279817
0.4960492478,0.3324569377,0.4629601291,0.6943913798
0.7832525712,0.7736390004,0.6018076366,0.459239076
0.3967061569,0.2262678901,0.0954549723,0.3667703934
0.0428036742,0.4119245463,0.9250495513,0.2355867573
0.4063226071,0.6730445873,0.8238667281,0.4870669091
0.5567263441,0.8210499264,0.2593653657,0.4608143963
0.5592416906,0.9012447973,0.0700987189,0.2749906528
0.6384119732,0.6510454672,0.3042892856,0.5826964585
0.9798633371,0.5523820339,0.5814304271,0.376491325
0.9628448317,0.7487761635,0.5941262873,0.3321952101
0.3706260702,0.252344383,0.7096924064,0.5166805546
0.218632948,0.994277475,0.7809678472,0.2316591283
0.3168673543,0.0835500112,0.2528727206,0.348299558
0.7906319198,0.2219688163,0.723273431,0.4060044512
0.1247621915,0.1237534864,0.525949755,0.3340120188
0.9565921184,0.3952253068,0.8622134365,0.2738660735
0.505859251,0.4401271036,0.7924990443,0.5674039286
0.3055876407,0.3310139194,0.9801331168,0.3211581991
0.6631613025,0.276597142,0.5381954648,0.586759686
0.1150634772,0.9736670898,0.2515394538,0.2070342949
0.8232522632,0.4894588125,0.8950760974,0.3554489991
0.4975627763,0.5231172818,0.4102074437,0.7732727653
0.6119855439,0.1610955916,0.4975586061,0.5090899468
0.682962104,0.0776563653,0.419031434,0.3986869975
0.6726203319,0.7876597129,0.9536890857,0.3017739741
0.0913773174,0.9450365906,0.7027720889,0.2287290962
0.602766628,0.7837863102,0.8969436441,0.3673672982
0.6155271592,0.9020927012,0.2874681981,0.3967761824
0.8478364911,0.5960036262,0.5907624708,0.4939437637
0.246004391,0.3808873582,0.0403679333,0.3275430665
0.4305861098,0.0345780167,0.2477172503,0.3320942318
0.5289812609,0.0837675568,0.7474209829,0.3809413873
0.9523989413,0.4010429585,0.1831988612,0.304936944
0.114349951,0.133078384,0.5551008282,0.3308679187

Producing following results:

original values at random points
interpolated values using griddata with linear interpolation


来源: stackexchange

问:
Bootstrap modal won't show up
My bootstrap (3.0.2) modal won't show up. I've tried different buttons, links and all that but it simply won't show up. I appreciate any help!

```<code><head>
    <link rel="stylesheet" href="css/bootstrap.min.css" />
</head>
<body>
    <button type="button" class="btn btn-success btn-sm" data-toggle="modal" data-target="#purchaseModal">Purchase</button>

    <div class="modal fade" id="purchaseModal" tabindex="-1" role="dialog" aria-labelledby="purchaseLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                    <h4 class="modal-title" id="purchaseLabel">Purchase</h4>
                </div>
                <div class="modal-body">
                    sup?
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                    <button type="button" class="btn btn-primary">Purchase</button>
                </div>
            </div>
        </div>
    </div>

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
    <script src="js/jquery-ui-1.10.3.custom.min.js"></script>
    <script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.2/js/bootstrap.min.js"></script>
</body>
</code>```

UPDATE 1:
Here's a screenshot of the warnings in the console.

UPDATE 2:
The button and the modal are located inside a container. Maybe this could help on your path to a solution?

答:
I have the same problem. when i add this code :

```<code>let postBody = event.target.parentNode.parentNode.childNodes[1].textContent;
</code>```

modal will not show up . and when i remove it the modal appears.

ContentLicense: CC BY-SA 3.0

Title: Bootstrap modal won't show up

Body:
My bootstrap (3.0.2) modal won't show up. I've tried different buttons, links and all that but it simply won't show up. I appreciate any help!

    <link rel="stylesheet" href="css/bootstrap.min.css" />

    <button type="button" class="btn btn-success btn-sm" data-toggle="modal" data-target="#purchaseModal">Purchase</button>

                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>

Purchase

                    sup?

                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                    <button type="button" class="btn btn-primary">Purchase</button>

UPDATE 1:
Here's a screenshot of the warnings in the console.

UPDATE 2:
The button and the modal are located inside a container. Maybe this could help on your path to a solution?

Body:
I have the same problem. when i add this code :

let postBody = event.target.parentNode.parentNode.childNodes[1].textContent;

modal will not show up . and when i remove it the modal appears.


问:
Using ioctl(), read() and malloc() to receive a message from server not working properly
I am trying to make a simple server client program in C. On the client I try to receive the message from the server, but the size of the message is not predetermined. Therefore, I want to check how many bytes are coming in, and malloc the appropriate size.

I tried to use ioctl but it seems like it gets the info I want too late.
This is what I have.

```<code>char *message_from_server;
int length;
while(1){
    ioctl(socket, FIONREAD, &length);
    message_from_server = malloc(length);
    read(socket, message_from_server, length);
}
</code>```

The first time I use it, length is 0. The second time, length is equal to that of the first message. If I put the line ioctl(socket, FIONREAD, &length); after i read, that might give me trouble with mallocing the correct amount of space. Is this even a valid way to solve my problem?

I have heard that one can use realloc to solve my problem, but I am struggling to see how to it so solve my problem. If that is a better way to do it, I would be happy for any tips.

Thanks!

答:
realloc allows you to increase the size of a memory block, preserving its content.

So, in your case:

read size of incoming packet

update memory block to store packet, preserving what have been read previously

read the packet

goto 1. or exit

Your code should look like:

```<code>/* memory to store message, initially, no memory */
char *message_from_server = NULL;
/* size of memory */
int total_length = 0;

/* sizeof incoming packet*/
int packet_lentgh;

/* position to write in memory */
int offset;

while(1){
    /* read size of incoming packet*/
    ioctl(socket, FIONREAD, &packet_lentgh);

    if (0 != packet_lentgh)
    {
        /* something is ready to be read on socket */

        /* update memory size */
        total_length += packet_lentgh;

        /* allocate much memory*/
        message_from_server = realloc(message_from_server, total_length);
        if (NULL == message_from_server)
        {
            perror("realloc");
            abort();
        }

        /* compute the position to write in memory */
        offset = total_length - packet_lentgh;

        /* read the packet */
        read(socket, message_from_server + offset, packet_lentgh);
    }
    else
    {
        /* nothing to read
           wait for packet or stop loop... */
    }
}
</code>```

Body:
I am trying to make a simple server client program in C. On the client I try to receive the message from the server, but the size of the message is not predetermined. Therefore, I want to check how many bytes are coming in, and malloc the appropriate size.

I tried to use ioctl but it seems like it gets the info I want too late.
This is what I have.

char *message_from_server;
int length;
while(1){
    ioctl(socket, FIONREAD, &length);
    message_from_server = malloc(length);
    read(socket, message_from_server, length);
}

The first time I use it, length is 0. The second time, length is equal to that of the first message. If I put the line ioctl(socket, FIONREAD, &length); after i read, that might give me trouble with mallocing the correct amount of space. Is this even a valid way to solve my problem?

I have heard that one can use realloc to solve my problem, but I am struggling to see how to it so solve my problem. If that is a better way to do it, I would be happy for any tips.

Thanks!

Body:
realloc allows you to increase the size of a memory block, preserving its content.

So, in your case:

read size of incoming packet

update memory block to store packet, preserving what have been read previously

read the packet

goto 1. or exit

Your code should look like:

/* memory to store message, initially, no memory */
char *message_from_server = NULL;
/* size of memory */
int total_length = 0;

/* sizeof incoming packet*/
int packet_lentgh;

/* position to write in memory */
int offset;

while(1){
    /* read size of incoming packet*/
    ioctl(socket, FIONREAD, &packet_lentgh);

    if (0 != packet_lentgh)
    {
        /* something is ready to be read on socket */

        /* update memory size */
        total_length += packet_lentgh;

        /* allocate much memory*/
        message_from_server = realloc(message_from_server, total_length);
        if (NULL == message_from_server)
        {
            perror("realloc");
            abort();
        }

        /* compute the position to write in memory */
        offset = total_length - packet_lentgh;

        /* read the packet */
        read(socket, message_from_server + offset, packet_lentgh);
    }
    else
    {
        /* nothing to read
           wait for packet or stop loop... */
    }
}


问:
Save Image ONLY if user selects "OK"
So this Code works the issue is that when I open the camera take a picture a "Retry" & "Ok" screen comes up, which is fine but when I tap the "Retry" the camera goes back into shooting mode (taking a picture) image is still loaded into the Bitmap and saves the image to the Dir when I hit the back key to exit the camera.

Is there a way not to save the image when I click Retry and exit the camera?
Or to only save when I select "OK"?

I am using this Camera API ParaCamera
Or should I use android build in camera api? if so h

```<code>public void takePhoto() {
    checkStoragePermissions();
    SharedPreferences unID = PreferenceManager.getDefaultSharedPreferences(getContext());
    imgID = unID.getString("unique_ID", "");
    camera = new Camera.Builder()
            .resetToCorrectOrientation(true)
            .setTakePhotoRequestCode(1)
            .setDirectory("/Pictures/WasThere/Images")
            .setName(imgID)
            .setImageFormat(Camera.IMAGE_JPEG)
            .setCompression(75)
            .setImageHeight(700)
            .build(this);
    try {
        camera.takePicture();
    }catch (Exception e){
        e.printStackTrace();
    }
}
    @Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if(requestCode == Camera.REQUEST_TAKE_PHOTO){
        Bitmap bitmap = camera.getCameraBitmap();
        if(bitmap != null) {
            captureImage.setImageBitmap(bitmap);
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    // this makes the image disapear in 6 Seconds
                    captureImage.setImageResource(R.color.transpar);
                }
            },6000);
            storeImage(bitmap);
        }else{
            Toast.makeText(getContext().getApplicationContext(),"Picture not taken!",Toast.LENGTH_SHORT).show();
        }
    }
}

private void storeImage(Bitmap image) {
    File pictureFile = getOutputMediaFile();
    if (pictureFile == null) {
        Log.d(TAG,
                "Error creating media file, check storage permissions: ");// e.getMessage());
        return;
    }
    try {
        FileOutputStream fos = new FileOutputStream(pictureFile);
        image.compress(Bitmap.CompressFormat.JPEG, 75, fos);
        fos.close();
    } catch (FileNotFoundException e) {
        Log.d(TAG, "File not found: " + e.getMessage());
    } catch (IOException e) {
        Log.d(TAG, "Error accessing file: " + e.getMessage());
    }
}

private  File getOutputMediaFile(){
    // To be safe, you should check that the SDCard is mounted
    //captureImage.setImageBitmap(camera.getCameraBitmap());
    File mediaStorageDir = new File(Environment.getExternalStorageDirectory().toString()
            + "/Pictures/WasThere");
    // This location works best if you want the created images to be shared
    // between applications and persist after your app has been uninstalled.
    // Create the storage directory if it does not exist
    if (! mediaStorageDir.exists()){
        if (! mediaStorageDir.mkdirs()){
            return null;
        }
    }
    // Create a media file name
    String timeStamp = new SimpleDateFormat("_dd_MM_yyyy_k:mm:ss").format(new Date());
    File mediaFile;
    String mImageName=imgID +timeStamp+".jpg";
    mediaFile = new File(mediaStorageDir.getPath()+File.separator + mImageName);
    //Gets the image current path
    mCurrentPhotoPath = mediaFile.getAbsolutePath();
    galleryAddPic();
    return mediaFile;

   }
</code>```

答:
You can change code in onActivityResult as,

if (requestCode == CAMERA_REQUEST_CODE && resultCode == Activity.RESULT_OK) {

Title: Save Image ONLY if user selects "OK"

Body:
So this Code works the issue is that when I open the camera take a picture a "Retry" & "Ok" screen comes up, which is fine but when I tap the "Retry" the camera goes back into shooting mode (taking a picture) image is still loaded into the Bitmap and saves the image to the Dir when I hit the back key to exit the camera.

Is there a way not to save the image when I click Retry and exit the camera?
Or to only save when I select "OK"?

I am using this Camera API ParaCamera
Or should I use android build in camera api? if so h

public void takePhoto() {
    checkStoragePermissions();
    SharedPreferences unID = PreferenceManager.getDefaultSharedPreferences(getContext());
    imgID = unID.getString("unique_ID", "");
    camera = new Camera.Builder()
            .resetToCorrectOrientation(true)
            .setTakePhotoRequestCode(1)
            .setDirectory("/Pictures/WasThere/Images")
            .setName(imgID)
            .setImageFormat(Camera.IMAGE_JPEG)
            .setCompression(75)
            .setImageHeight(700)
            .build(this);
    try {
        camera.takePicture();
    }catch (Exception e){
        e.printStackTrace();
    }
}
    @Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if(requestCode == Camera.REQUEST_TAKE_PHOTO){
        Bitmap bitmap = camera.getCameraBitmap();
        if(bitmap != null) {
            captureImage.setImageBitmap(bitmap);
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    // this makes the image disapear in 6 Seconds
                    captureImage.setImageResource(R.color.transpar);
                }
            },6000);
            storeImage(bitmap);
        }else{
            Toast.makeText(getContext().getApplicationContext(),"Picture not taken!",Toast.LENGTH_SHORT).show();
        }
    }
}

private void storeImage(Bitmap image) {
    File pictureFile = getOutputMediaFile();
    if (pictureFile == null) {
        Log.d(TAG,
                "Error creating media file, check storage permissions: ");// e.getMessage());
        return;
    }
    try {
        FileOutputStream fos = new FileOutputStream(pictureFile);
        image.compress(Bitmap.CompressFormat.JPEG, 75, fos);
        fos.close();
    } catch (FileNotFoundException e) {
        Log.d(TAG, "File not found: " + e.getMessage());
    } catch (IOException e) {
        Log.d(TAG, "Error accessing file: " + e.getMessage());
    }
}

private  File getOutputMediaFile(){
    // To be safe, you should check that the SDCard is mounted
    //captureImage.setImageBitmap(camera.getCameraBitmap());
    File mediaStorageDir = new File(Environment.getExternalStorageDirectory().toString()
            + "/Pictures/WasThere");
    // This location works best if you want the created images to be shared
    // between applications and persist after your app has been uninstalled.
    // Create the storage directory if it does not exist
    if (! mediaStorageDir.exists()){
        if (! mediaStorageDir.mkdirs()){
            return null;
        }
    }
    // Create a media file name
    String timeStamp = new SimpleDateFormat("_dd_MM_yyyy_k:mm:ss").format(new Date());
    File mediaFile;
    String mImageName=imgID +timeStamp+".jpg";
    mediaFile = new File(mediaStorageDir.getPath()+File.separator + mImageName);
    //Gets the image current path
    mCurrentPhotoPath = mediaFile.getAbsolutePath();
    galleryAddPic();
    return mediaFile;

   }


问:
IntelliJ. What does PSI stand for?
I'd like to develop IntelliJ plugin and have small question.

https://www.jetbrains.com/help/idea/psi-viewer.html

In above document, what does PSI mean?

答:
Oh I got it. It's Program Structure Interface.

http://www.jetbrains.org/intellij/sdk/docs/basics/architectural_overview/psi_elements.html

Someone complained PSI meaning like me a year ago: link

Title: IntelliJ. What does PSI stand for?


问:
Time Complexity of searching
there is a sorted array which is of very large size. every element is repeated more than once except one element. how much time will it take to find that element?

Options are:

1.O(1)

2.O(n)

3.O(logn)

4.O(nlogn)

答:
The answer to the question is O(n) and here's why.

Let's first summarize the knowledge we're given:

A large array containing elements

The array is sorted

Every item except for one occurs more than once

Question is what is the time growth of searching for that one item that only occurs once?

The sorted property of the array, can we use this to speed up the search for the item? Yes, and no.

First of all, since the array isn't sorted by the property we must use to look for the item (only one occurrence) then we cannot use the sorted property in this regard. This means that optimized search algorithms, such as binary search, is out.

However, we know that if the array is sorted, then all items that have the same value will be grouped together. This means that when we look at an item we see for the first time we only have to compare it to the following item. If it's different, we've found the item we're looking for.

"see for the first time" is important, otherwise we would pick the first value since there will be a boundary between two groups of items where the two items are different.

So we have to move from one end of the array to the other, and compare each item to the following item, and this is an O(n) operation.

Basically, since the array isn't sorted by the property we're looking at, we're back to a linear search.

Title: Time Complexity of searching


问:
How do i synchronize an entity after saving a child object to the database?
I have a User object that gets loaded from the database during user login. This user has a OneToMany relationship (messageList) with the Message entity. When another user sends a new message to that user this message is stored in the database. After that has happened I need to have the messageList of the logged in user to be synchronized automatically with the Database. In other words, the new message needs to appear in the messageList list of the receiving user.

Is there a Spring-data way of accomplishing this? I prefer not to refresh the entire userEntity after the message has been saved. (Using entitymanager.refresh()) because it seems like overkill to retrieve all the child objects inside the userEntity just for the sake of synchronizing the messageList.

I could add the new message to the userEntity and then save the userEntity, but sometimes the same message gets sent to multiple users and I don't want to have to retrieve all the user object just to be able to save a message.

The solution I currently have is to make a Spring AspectJ listener method that listens to all methods saving a message. When that happens the save message gets manually added to the concerning user entity messageList. Why all this effort you may ask? Because I want the message to automatically appear in the frontend (I'm using Angular 4 framework). Angular 4 listens for changes in the data model.

But before I implement this solution I was wondering whether there is a more simpler way of achieving messagelist synchronization.

Thank you.

答:
I think the main problem is that you consider the Messages to be part of the User. From your description it seems the User consists of more or less static information, while Messages appear often.

So I propose to change the domain model to have Message as a separate Aggregate Root with its own repository. The repository should probably have a method to get all the Messages for a User and maybe another one for getting all the messages that happened for a User after a certain timestamp or a different Message allowing you to get just the new Messages.

Another question is, if you are using the correct technology for the job. Distributing events via relational database is possible but they aren't exactly build for this. You might want to consider alternatives like an in memory store (e.g. Hazelcast) or a dedicated messaging solution (e.g. RabbitMQ). Note that the Messages can (and possibly should) still be saved in a persistent store, but not to use that store for distributing it.


问:
Logging with Retrofit 2
I'm trying to get the exact JSON that is being sent in the request. Here is my code:

OkHttpClient client = new OkHttpClient();
client.interceptors().add(new Interceptor(){
   @Override public com.squareup.okhttp.Response intercept(Chain chain) throws IOException {
      Request request = chain.request();
      Log.e(String.format("\nrequest:\n%s\nheaders:\n%s",
                          request.body().toString(), request.headers()));
      com.squareup.okhttp.Response response = chain.proceed(request);
      return response;
   }
});
Retrofit retrofit = new Retrofit.Builder()
   .baseUrl(API_URL)
   .addConverterFactory(GsonConverterFactory.create())
   .client(client).build();
```

<p>But I only see this in the logs:</p>

```request:
com.squareup.okhttp.RequestBody$1@3ff4074d
headers:
Content-Type: application/vnd.ll.event.list+json
```

How am I supposed to do proper logging, given the removal of setLog() and setLogLevel() which we used to use with Retrofit 1?

答:
for Retrofit 2.0.2 the code is like:

HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
        logging.setLevel(HttpLoggingInterceptor.Level.BODY);
        OkHttpClient.Builder httpClient=new OkHttpClient.Builder();
        httpClient.addInterceptor(logging);

        if (retrofit == null) {
            retrofit = new Retrofit.Builder()
                    .baseUrl(BASE_URL)
                    .addConverterFactory(GsonConverterFactory.create())
                    .client(httpClient.build())
                    .build();
        }
```

Title: Logging with Retrofit 2

Body:
I'm trying to get the exact JSON that is being sent in the request. Here is my code:

OkHttpClient client = new OkHttpClient();
client.interceptors().add(new Interceptor(){
   @Override public com.squareup.okhttp.Response intercept(Chain chain) throws IOException {
      Request request = chain.request();
      Log.e(String.format("\nrequest:\n%s\nheaders:\n%s",
                          request.body().toString(), request.headers()));
      com.squareup.okhttp.Response response = chain.proceed(request);
      return response;
   }
});
Retrofit retrofit = new Retrofit.Builder()
   .baseUrl(API_URL)
   .addConverterFactory(GsonConverterFactory.create())
   .client(client).build();

But I only see this in the logs:

request:
com.squareup.okhttp.RequestBody$1@3ff4074d
headers:
Content-Type: application/vnd.ll.event.list+json

How am I supposed to do proper logging, given the removal of setLog() and setLogLevel() which we used to use with Retrofit 1?

ContentLicense: CC BY-SA 4.0


问:
Python BeautifulSoup remove items with
 tags from list
I have a BeautifulSoup object (web page), and I've honed in on one HTML paragraph of interest. It has several items in it, and I'd like to clean out the junk (anything other than text).

I have the items from the paragraph in a list after calling the paragraph's Contents attribute (e.g. paragraph_name.contents), but need help clearing out the items with HTML tags in the list.

Here's what the list looks like:

```<code>[u'\n',
 <span>Early Education Enrollment: 0</span>,
 <br/>,
 u'\r\n        Elementary Enrollment: 231',
 <br/>,
 u'\r\n        Middle School Enrollment: 118',
 <br/>,
 u'\r\n        High School Enrollment: 121',
 <br/>,
 u'\r\n        Total Enrollment: 470',
 <br/>,
 u'\n',
 <span>I20: True</span>,
 <br/>,
 u'\r\n                                                Grade Levels: K - 12',
 <br/>,
 u'\r\n        Year Founded: 1999',
 <br/>,
 u'\n',
 <span>Other Accreditation: AdvancED, SACS</span>,
 u'\n']
</code>```

Here is all the code you'll need to recreate the exact issue I'm having on your machine so we can truly work the same problem:

```<code>from bs4 import BeautifulSoup as BS
# the sample html as a BeautifulSoup Object:
soup = BS('<p>\n<span>Early Education Enrollment: 0</span><br/>\r\n        Elementary Enrollment: 231<br/>\r\n        Middle School Enrollment: 118<br/>\r\n        High School Enrollment: 121<br/>\r\n        Total Enrollment: 470<br/>\n<span>I20: True</span><br/>\r\n                                                Grade Levels: K - 12<br/>\r\n        Year Founded: 1999<br/>\n<span>Other Accreditation: AdvancED, SACS</span>\n</p>', 'lxml')
# hone in on the paragraph I want to parse through:
target_p = soup.find('p')
# organize paragraph items into a list, although including junk for now:
dirty_list = target_p.contents
# clean up list using method I need help with:
clean_list =
</code>```

I figured list comprehensions were the way to go, but can't figure out how to hone in on the html tags. This doesn't work:

```<code>clean_list = [x for x in dirty_list if x != '<br/>']
</code>```

Thank you!

答:
It depends what output format you are looking for. Using soup.p.text will give you all the text, but this will include leading spaces. Python can be used to split the text into lines and strip the extra space from each line. This can then be joined back together if required:

```<code>from bs4 import BeautifulSoup as BS

soup = BS('<p>\n<span>Early Education Enrollment: 0</span><br/>\r\n        Elementary Enrollment: 231<br/>\r\n        Middle School Enrollment: 118<br/>\r\n        High School Enrollment: 121<br/>\r\n        Total Enrollment: 470<br/>\n<span>I20: True</span><br/>\r\n                                                Grade Levels: K - 12<br/>\r\n        Year Founded: 1999<br/>\n<span>Other Accreditation: AdvancED, SACS</span>\n</p>', 'lxml')
print '\n'.join(line.strip() for line in soup.p.text.split('\n'))
</code>```

Giving you:

Early Education Enrollment: 0
Elementary Enrollment: 231
Middle School Enrollment: 118
High School Enrollment: 121
Total Enrollment: 470
I20: True
Grade Levels: K - 12
Year Founded: 1999
Other Accreditation: AdvancED, SACS
```

Title: Python BeautifulSoup remove items with <br/> tags from list

Body:
I have a BeautifulSoup object (web page), and I've honed in on one HTML paragraph of interest. It has several items in it, and I'd like to clean out the junk (anything other than text).

I have the items from the paragraph in a list after calling the paragraph's Contents attribute (e.g. paragraph_name.contents), but need help clearing out the items with HTML tags in the list.

Here's what the list looks like:

[u'\n',
 Early Education Enrollment: 0,

,
 u'\r\n        Elementary Enrollment: 231',

,
 u'\r\n        Middle School Enrollment: 118',

,
 u'\r\n        High School Enrollment: 121',

,
 u'\r\n        Total Enrollment: 470',

,
 u'\n',
 I20: True,

,
 u'\r\n                                                Grade Levels: K - 12',

,
 u'\r\n        Year Founded: 1999',

,
 u'\n',
 Other Accreditation: AdvancED, SACS,
 u'\n']

Here is all the code you'll need to recreate the exact issue I'm having on your machine so we can truly work the same problem:

from bs4 import BeautifulSoup as BS
# the sample html as a BeautifulSoup Object:
soup = BS('
\nEarly Education Enrollment: 0
\r\n        Elementary Enrollment: 231
\r\n        Middle School Enrollment: 118
\r\n        High School Enrollment: 121
\r\n        Total Enrollment: 470
\nI20: True
\r\n                                                Grade Levels: K - 12
\r\n        Year Founded: 1999
\nOther Accreditation: AdvancED, SACS\n
', 'lxml')
# hone in on the paragraph I want to parse through:
target_p = soup.find('p')
# organize paragraph items into a list, although including junk for now:
dirty_list = target_p.contents
# clean up list using method I need help with:
clean_list =

I figured list comprehensions were the way to go, but can't figure out how to hone in on the html tags. This doesn't work:

clean_list = [x for x in dirty_list if x != '
']

Thank you!

Body:
It depends what output format you are looking for. Using soup.p.text will give you all the text, but this will include leading spaces. Python can be used to split the text into lines and strip the extra space from each line. This can then be joined back together if required:

from bs4 import BeautifulSoup as BS

soup = BS('<p>\n<span>Early Education Enrollment: 0</span><br/>\r\n        Elementary Enrollment: 231<br/>\r\n        Middle School Enrollment: 118<br/>\r\n        High School Enrollment: 121<br/>\r\n        Total Enrollment: 470<br/>\n<span>I20: True</span><br/>\r\n                                                Grade Levels: K - 12<br/>\r\n        Year Founded: 1999<br/>\n<span>Other Accreditation: AdvancED, SACS</span>\n</p>', 'lxml')
print '\n'.join(line.strip() for line in soup.p.text.split('\n'))

Giving you:

Early Education Enrollment: 0
Elementary Enrollment: 231
Middle School Enrollment: 118
High School Enrollment: 121
Total Enrollment: 470
I20: True
Grade Levels: K - 12
Year Founded: 1999
Other Accreditation: AdvancED, SACS


问:
Hibernate's Delete Method giving StaleStateException
I am trying to delete object using Hibernate's delete method but getting StaleStateException exception.My requirement is to delete an object based on the unique key so for this i am doing something like.

```<code>String queryString="from Destination destination "+
                                                   "where destination.destinationID = :destinationid";
    tx.begin();
                Query query= session.createQuery(queryString).setParameter("destinationid", destinationId, Hibernate.STRING);
               @SuppressWarnings("unchecked")
               List<Destination> list=query.list();
               Destination ds=list.get(0);
                 if(!list.isEmpty())
                  session.evict(ds);
                  session.delete(ds);

                  tx.commit();
</code>```

since i know there will be only one element in the list if its not empty so only fetching the first element from the list (Not sure if this is a good approach)

but when i am running this method i can see the following sql log in my console

```<code>Hibernate:
    /* delete collection AirTransport.timeTable */ delete
        from
            tr.TRANSPORTTIME
        where
            TRANSPORTID=?
Hibernate:
    /* delete collection AirTransport.timeTable */ delete
        from
            tr.TRANSPORTTIME
        where
            TRANSPORTID=?
Hibernate:
    /* delete collection AirTransport.timeTable */ delete
        from
            tr.TRANSPORTTIME
        where
            TRANSPORTID=?
Hibernate:
    /* delete collection RoadTransport.timeTable */ delete
        from
            tr.TRANSPORTTIME
        where
            TRANSPORTID=?
Hibernate:
    /* delete collection TrainTransport.timeTable */ delete
        from
            tr.TRANSPORTTIME
        where
            TRANSPORTID=?
Hibernate:
    /* delete AirTransport */ delete
        from
            tr.TRANSPORT
        where
            UUID=?
Hibernate:
    /* delete AirTransport */ delete
        from
            tr.TRANSPORT
        where
            UUID=?
Hibernate:
    /* delete AirTransport */ delete
        from
            tr.TRANSPORT
        where
            UUID=?
Hibernate:
    /* delete RoadTransport */ delete
        from
            tr.TRANSPORT
        where
            UUID=?
</code>```

and than its throwing

```<code>org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
 at org.hibernate.jdbc.Expectations$BasicExpectation.checkBatched(Expectations.java:61)
 at org.hibernate.jdbc.Expectations$BasicExpectation.verifyOutcome(Expectations.java:46)
</code>```

one thing which making me suspicious is that in my Transport table i have three entries only one for AirTransport one for Train and last one for Road and in the TransPortTime table i have three entries one for each Transport type and

i am using TransportTime as composite-element in side all three transport classes

```<code><set name="timeTable" table="TRANSPORTTIME" lazy="true">
                        <key column="TRANSPORTID"/>
                        <composite-element
                                class="TransportTime">

                                <property name="deperatureTime" type="java.util.Date">
                                        <column name="DEPERATURETIME" />
                                </property>
                                <property name="arrivalTime" type="java.util.Date">
                                        <column name="ARRIVALTIME" />
                                </property>
                                <other properties>
                        </composite-element>

                </set>
</code>```

i am still unable to figure out whats going wrong so though of asking in the community

Just to add some extra information:
i have the below mapping in my destination class for the three respective trabsport classes

```<code><set name="airTransport" table="AIRTRANSPORT" inverse="true" lazy="true" cascade="save-update, delete">
        <key>
            <column name="DESTINATIONID" />
        </key>
        <one-to-many class="AirTransport" />
    </set>
    <set name="roadTransport" table="ROADTRANSPORT" inverse="true" lazy="true" cascade="save-update, delete">
        <key>
            <column name="DESTINATIONID" />
        </key>
        <one-to-many class="RoadTransport" />
    </set>
    <set name="trainTransport" table="TRAINTRANSPORT" inverse="true" lazy="true" cascade="save-update, delete">
        <key>
            <column name="DESTINATIONID" />
        </key>
        <one-to-many class="TrainTransport" />
    </set>
</code>```

and in my RoadTransport/Train/Air Transport have following mapping

```<code><class name="AirTransport" table="TRANSPORT">
        <id name="uuid" type="java.lang.String">
            <column name="UUID" />
            <generator class="uuid"/>
        </id>
        <many-to-one name="destination" class="Destination" fetch="join">
            <column name="DESTINATIONID" />
        </many-to-one>
       <property mappings>
        <set name="timeTable" table="TRANSPORTTIME" lazy="true">
            <key column="TRANSPORTID"/>
            <composite-element
                class="TransportTime">
                <property mappings>
                </composite-element>

        </set>
    </class>
</code>```

Other two mapping files are also identical
so when i removed mapping association of these three classes from parent class my delete functionality started working perfectly.

So this means i am doing fundamenally wrong in mapping the TimeTable class as component inside Transport classes (Air/Train/Road Transport class)

any suggestion in this regard will be much helpfull

答:
StaleStateException is thrown when a version number or timestamp check failed, indicating that the Session contained stale data (when using long transactions with versioning). Also occurs if we try delete or update a row that does not exist.

Note that this exception often indicates that the user failed to specify the correct unsaved-value strategy for a class!

http://www.dil.univ-mrs.fr/~massat/docs/hibernate-3.1/api/org/hibernate/StaleStateException.html

My guess is, your row is updated during this long transaction. And when it tries to commit delete, it sees that the versions are different (the one in your session marked to be deleted and the actual row in db) so a StaleStateException is thrown

Also Query class should have some method called uniqueResult() which will return one object result if you are sure it is gonna return one result each and every time you execute it. That will save you some code at trying to get 0th index of List part.

ContentLicense: CC BY-SA 2.5

Body:
I am trying to delete object using Hibernate's delete method but getting StaleStateException exception.My requirement is to delete an object based on the unique key so for this i am doing something like.

String queryString="from Destination destination "+
                                                   "where destination.destinationID = :destinationid";
    tx.begin();
                Query query= session.createQuery(queryString).setParameter("destinationid", destinationId, Hibernate.STRING);
               @SuppressWarnings("unchecked")
               List<Destination> list=query.list();
               Destination ds=list.get(0);
                 if(!list.isEmpty())
                  session.evict(ds);
                  session.delete(ds);

                  tx.commit();

since i know there will be only one element in the list if its not empty so only fetching the first element from the list (Not sure if this is a good approach)

but when i am running this method i can see the following sql log in my console

Hibernate:
    /* delete collection AirTransport.timeTable */ delete
        from
            tr.TRANSPORTTIME
        where
            TRANSPORTID=?
Hibernate:
    /* delete collection AirTransport.timeTable */ delete
        from
            tr.TRANSPORTTIME
        where
            TRANSPORTID=?
Hibernate:
    /* delete collection AirTransport.timeTable */ delete
        from
            tr.TRANSPORTTIME
        where
            TRANSPORTID=?
Hibernate:
    /* delete collection RoadTransport.timeTable */ delete
        from
            tr.TRANSPORTTIME
        where
            TRANSPORTID=?
Hibernate:
    /* delete collection TrainTransport.timeTable */ delete
        from
            tr.TRANSPORTTIME
        where
            TRANSPORTID=?
Hibernate:
    /* delete AirTransport */ delete
        from
            tr.TRANSPORT
        where
            UUID=?
Hibernate:
    /* delete AirTransport */ delete
        from
            tr.TRANSPORT
        where
            UUID=?
Hibernate:
    /* delete AirTransport */ delete
        from
            tr.TRANSPORT
        where
            UUID=?
Hibernate:
    /* delete RoadTransport */ delete
        from
            tr.TRANSPORT
        where
            UUID=?

and than its throwing

org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
 at org.hibernate.jdbc.Expectations$BasicExpectation.checkBatched(Expectations.java:61)
 at org.hibernate.jdbc.Expectations$BasicExpectation.verifyOutcome(Expectations.java:46)

one thing which making me suspicious is that in my Transport table i have three entries only one for AirTransport one for Train and last one for Road and in the TransPortTime table i have three entries one for each Transport type and

i am using TransportTime as composite-element in side all three transport classes

<set name="timeTable" table="TRANSPORTTIME" lazy="true">
                        <key column="TRANSPORTID"/>
                        <composite-element
                                class="TransportTime">

                                <property name="deperatureTime" type="java.util.Date">
                                        <column name="DEPERATURETIME" />
                                </property>
                                <property name="arrivalTime" type="java.util.Date">
                                        <column name="ARRIVALTIME" />
                                </property>
                                <other properties>
                        </composite-element>

                </set>

i am still unable to figure out whats going wrong so though of asking in the community

Just to add some extra information:
i have the below mapping in my destination class for the three respective trabsport classes

<set name="airTransport" table="AIRTRANSPORT" inverse="true" lazy="true" cascade="save-update, delete">
        <key>
            <column name="DESTINATIONID" />
        </key>
        <one-to-many class="AirTransport" />
    </set>
    <set name="roadTransport" table="ROADTRANSPORT" inverse="true" lazy="true" cascade="save-update, delete">
        <key>
            <column name="DESTINATIONID" />
        </key>
        <one-to-many class="RoadTransport" />
    </set>
    <set name="trainTransport" table="TRAINTRANSPORT" inverse="true" lazy="true" cascade="save-update, delete">
        <key>
            <column name="DESTINATIONID" />
        </key>
        <one-to-many class="TrainTransport" />
    </set>

and in my RoadTransport/Train/Air Transport have following mapping

<class name="AirTransport" table="TRANSPORT">
        <id name="uuid" type="java.lang.String">
            <column name="UUID" />
            <generator class="uuid"/>
        </id>
        <many-to-one name="destination" class="Destination" fetch="join">
            <column name="DESTINATIONID" />
        </many-to-one>
       <property mappings>
        <set name="timeTable" table="TRANSPORTTIME" lazy="true">
            <key column="TRANSPORTID"/>
            <composite-element
                class="TransportTime">
                <property mappings>
                </composite-element>

        </set>
    </class>

Other two mapping files are also identical
so when i removed mapping association of these three classes from parent class my delete functionality started working perfectly.

So this means i am doing fundamenally wrong in mapping the TimeTable class as component inside Transport classes (Air/Train/Road Transport class)

any suggestion in this regard will be much helpfull