我是python的新手,我试图根据数组的特定索引值而不是元素的值从数组中提取特定值。我该怎么办?
我知道我想从哪个数组中提取数据以及要提取的索引,但是我不确定函数设置。
我想从臀部角度文件中提取数据并提取特定的索引。
def hpst(demands):
hp = demands['HP'][:,0]
# fk = demands['FK'][:,0]
# aa = demands['AA'][:,0]
# val = (demands['StridePeaks'][:,0])
# hpst = {}
for A in range(len(hp)):
return A[[15,33,51,73,88,109,125,145,161,182,200,222,238]]
我不确定这是否是正确的设置。 但是,这是来自熊猫词典的臀部角度数据。我只想从0列以及索引15、33等处提取数据。
142.444 94.3356
132.121 92.7187
122.649 92.2527
112.534 103.177
100.118 102.765
92.0133 93.1956
86.4117 89.6813
77.5857 90.1729
70.9326 95.0486
67.0381 100.924
66.5811 110.449
69.5347 125.725
71.2853 139.804
73.4733 138.542
74.1935 127.868
73.7101 128.108
75.4367 128.032
77.7155 127.292
81.593 135.946
82.7716 128.468
79.9823 107.518
80.7256 100.981
84.3518 96.2074
85.6058 86.0201
83.7879 87.4381
85.4597 93.5943
89.8181 92.0666
97.5656 90.6827
116.002 89.9328
135.595 88.8136
150.94 91.4732
157.737 88.6928
155.49 84.379
156.55 87.471
155.458 89.4682
153.036 93.9603
153.757 98.5537
145.86 96.0115
134.803 100.779
126.987 107.122
111.637 102.514
95.01 97.033
89.0428 93.2397
84.2956 88.3167
73.1231 85.827
65.6818 85.3847
66.7661 88.2002
66.9876 102.567
65.6378 123.309
67.0576 138.525
72.153 142.375
77.9615 134.473
78.7077 129.01
79.3094 132.146
79.6939 133.914
77.8669 132.105
79.4663 125.982
80.7738 113.921
81.9972 105.029
86.7038 96.5438
86.8284 84.9008
83.2474 87.0168
86.8545 95.0353
89.5397 88.5338
90.7755 87.7473
105.112 99.8809
122.347 98.6513
137.134 95.2858
152.183 101.437
158.137 100.553
156.484 96.2948
153.716 96.7974
154.801 102.498
152.89 104.698
143.468 98.8762
138.304 95.86
128.719 94.8656
114.043 95.6951
107.558 96.4558
101.166 93.4559
93.7206 93.5208
85.3982 90.5242
75.906 87.6068
72.278 90.3149
70.2718 91.2148
69.3056 103.069
70.011 120.223
71.3477 124.454
76.9937 126.978
80.8508 131.451
80.0341 130.221
80.4728 122.764
81.5849 116.894
81.7331 114.3
80.66 104.565
80.688 95.5776
83.5644 91.9178
84.0912 87.5472
83.9085 88.8345
87.5639 88.372
92.5143 87.5451
97.9724 95.4833
108.694 98.5047
125.099 93.46
140.345 92.2416
157.075 98.5277
169.54 99.8388
168.204 99.911
162.676 103.14
155.131 97.1475
150.646 98.1131
152.127 106.245
149.424 111.988
141.379 113.049
124.835 95.792
107.939 88.8298
98.8121 96.6449
88.9631 92.1304
81.1267 90.0516
73.6213 90.3448
67.3936 86.9272
69.2013 94.6061
68.7782 113.364
67.1497 128.624
72.419 133.438
77.1528 132.73
76.2917 126.883
75.8093 123.265
77.8584 124.75
77.9565 122.36
78.0597 118.024
80.5439 108.822
81.6859 99.0825
81.1073 91.7428
80.6491 85.872
82.9748 92.8926
84.5156 89.72
82.8995 79.0692
93.4305 87.1985
115.421 91.5762
134.818 91.9185
148.396 92.6058
155.7 91.8545
157.929 91.8012
156.029 89.0408
155.537 103.305
152.636 106.649
143.85 91.4026
139.15 95.9343
134.295 101.185
120.378 101.393
109.157 104.284
100.904 103.878
92.7664 101.406
85.2396 91.9995
76.9565 80.6445
74.7453 86.9655
60.4233 105.397
76.727 89.4368
106.752 80.918
76.3472 122.442
63.0862 136.702
75.857 124.376
72.2408 127.796
74.3019 128.157
73.7003 126.903
75.6378 126.893
80.1898 119.195
79.818 107.194
78.0927 95.9515
78.6968 90.6118
81.6341 92.9499
81.8974 94.8118
85.8516 94.3597
91.5325 94.9903
100.875 94.3432
122.649 92.9595
143.269 90.4793
153.609 88.9303
159.759 93.486
162.477 102.913
158.822 107.012
154.776 105.631
155.569 108.909
152.73 103.638
146.952 93.7555
139.01 101.398
123.76 107.7
112.718 102.206
106.651 101.55
96.8904 97.5473
89.2883 91.0048
82.4354 86.8519
73.3603 85.9089
67.0828 98.7009
63.467 84.9501
64.4223 76.5582
67.4855 122.781
69.9852 140.948
73.8453 130.218
72.9275 130.016
72.6492 121.706
75.903 120.577
76.0476 122.544
78.4037 119.37
80.7675 112.94
82.5817 99.982
86.3209 93.482
85.0229 94.9573
84.1585 99.5623
86.933 98.3248
86.9423 87.0122
90.3343 85.6848
103.944 93.6842
123.422 91.7796
140.788 89.9716
154.369 92.1987
165.511 89.7282
167.283 90.7866
162.989 93.755
162.456 97.8036
156.689 97.0894
149.863 92.3949
148.294 99.2785
136.549 96.2237
123.03 92.4155
111.187 100.863
94.6514 96.2559
88.9702 95.7135
86.7612 92.5555
78.0158 85.3122
68.8636 90.824
62.4144 82.137
64.6031 86.899
65.628 117.267
62.1972 132.161
65.9919 137.014
70.3412 137.643
70.6389 133.078
71.8256 130.303
72.4533 126.325
74.2835 124.771
77.3096 123.649
77.6268 116.093
77.708 105.539
78.4 93.3733
78.7506 86.8869
79.7636 91.1909
82.4384 94.0581
85.8938 90.8869
87.6994 85.0496
94.2127 84.5761
111.206 91.2272
132.669 91.6249
150.309 89.9407
160.821 90.4688
164.157 89.0467
161.775 92.7846
158.439 99.413
156.53 100.486
151.654 94.4403
141.89 92.9437
133.617 93.4393
123.511 83.0772
107.083 84.3018
95.5675 96.8183
91.9259 95.9605
87.6419 90.4093
78.7722 87.534
基本上我想从臀部角度数据数组中的那些索引中提取角度。
答案 0 :(得分:0)
我认为没有一种方法可以在一个语句中做到这一点,但是您可以使用列表理解在两个语句中做到这一点:
indices = [0,15,33,51,73,88,109,125,145,161,182,200,222,238]
return [A[i] for i in indices]
至于一般的切片语法:
arr[start:end:step]
因此,进行A[3:10:2]
将从索引3
开始,直到达到索引10
,每次都增加两个元素(您也可以对这些索引使用负数;这些计数从列表的后面而不是前面)。所以,你会得到
A[3:10:2] --> [A[3], A[5], A[7], A[9]]
如果将start
空白,则从列表的开头开始。如果将end
留为空白,它将一直显示到列表末尾。并且,如果您将step
留空,则默认为1
,或将每个元素从start
移至end
。