我有两个要用来产生点积的数据框。我认为这很简单。但是我一直收到错误消息。 这是我的数据的样子(简化数据) 数据1:
0 4 6
-0.276 4403 4403
-0.138 4640 4640
0 0 0
0.138 12 0
0.276 0 0
0.414 0 0
0.552 0 0
0.69 0 0
0.828 0 12
0.966 0 0
1.104 0 12
1.242 0 0
1.38 0 0
1.518 0 0
1.656 0 0
1.794 0 0
1.932 0 0
2.07 0 0
2.208 0 0
2.346 0 0
2.484 0 0
2.622 0 12
2.76 0 0
2.898 0 0
3.036 0 0
3.174 0 0
3.312 0 0
3.45 0 0
3.588 0 0
3.726 0 0
3.864 12 0
4.002 0 0
4.14 0 0
4.278 12 0
4.416 0 0
4.554 0 12
4.692 0 0
4.83 0 0
4.968 0 0
5.106 0 0
5.244 0 0
5.382 12 0
5.52 0 0
5.658 0 0
5.796 127 60
5.934 357 275
6.072 1882 2144
6.21 6726 6609
6.348 9398 11180
6.486 12784 18389
6.624 15863 20111
6.762 6739 10202
6.9 1684 1921
7.038 249 376
7.176 47 103
7.314 0 26
7.452 17 0
7.59 0 0
7.728 0 0
7.866 0 0
8.004 0 0
8.142 0 0
8.28 0 0
8.418 0 0
8.556 0 0
8.694 0 0
8.832 0 0
8.97 0 0
9.108 0 0
9.246 0 0
9.384 0 0
9.522 0 0
9.66 0 0
9.798 0 0
9.936 0 0
10.074 0 0
10.212 0 0
10.35 0 12
10.488 0 0
10.626 0 0
10.764 0 0
10.902 0 0
11.04 0 0
11.178 0 0
11.316 0 0
11.454 0 0
11.592 0 0
11.73 0 0
11.868 0 0
12.006 0 0
12.144 0 0
12.282 0 0
12.42 0 0
12.558 0 0
12.696 12 0
12.834 0 0
12.972 0 0
13.11 0 0
13.248 0 0
13.386 12 0
13.524 0 0
13.662 0 12
13.8 0 0
13.938 0 0
14.076 0 0
14.214 0 0
14.352 0 0
14.49 0 0
14.628 12 0
14.766 0 0
14.904 12 0
15.042 0 0
15.18 0 0
15.318 0 0
15.456 0 0
15.594 0 0
15.732 0 0
15.87 0 0
16.008 0 0
16.146 0 0
16.284 0 0
16.422 0 0
16.56 12 0
16.698 0 0
16.836 0 0
16.974 0 0
17.112 0 0
17.25 0 0
17.388 0 0
17.526 0 0
17.664 0 12
17.802 0 0
17.94 0 0
18.078 0 0
18.216 0 0
18.354 0 0
18.492 0 0
18.63 12 0
18.768 0 0
18.906 0 0
19.044 0 0
19.182 0 0
19.32 0 0
19.458 0 0
19.596 0 0
19.734 0 0
19.872 0 0
20.01 0 0
20.148 0 12
20.286 12 0
20.424 0 12
20.562 0 0
20.7 0 0
20.838 0 0
20.976 0 0
21.114 0 0
21.252 0 0
21.39 0 12
21.528 0 0
21.666 0 0
21.804 12 0
21.942 0 0
22.08 0 0
22.218 0 0
22.356 0 0
22.494 0 0
22.632 0 0
22.77 0 0
22.908 0 0
23.046 0 0
23.184 0 0
23.322 0 0
23.46 12 0
23.598 0 12
23.736 0 0
23.874 0 0
24.012 0 0
24.15 0 0
24.288 0 0
24.426 0 0
24.564 0 0
24.702 0 0
24.84 0 0
24.978 0 0
25.116 0 0
25.254 0 0
25.392 0 0
25.53 0 0
25.668 0 0
25.806 12 0
25.944 12 0
26.082 0 0
26.22 0 0
26.358 0 12
26.496 0 0
26.634 0 0
26.772 0 0
26.91 0 0
27.048 13 0
27.186 0 0
27.324 0 0
27.462 0 0
数据2:
0 4 6
-0.276 4400 4400
-0.138 4750 4750
0 0 0
0.138 12 0
0.276 0 0
0.414 0 12
0.552 0 0
0.69 0 25
0.828 0 0
0.966 12 13
1.104 0 0
1.242 0 12
1.38 0 0
1.518 12 0
1.656 0 0
1.794 0 12
1.932 0 0
2.07 12 0
2.208 0 0
2.346 0 0
2.484 12 0
2.622 0 0
2.76 24 0
2.898 0 0
3.036 0 0
3.174 12 0
3.312 0 0
3.45 0 0
3.588 0 12
3.726 39 0
3.864 0 12
4.002 0 0
4.14 0 12
4.278 0 0
4.416 0 0
4.554 0 0
4.692 0 0
4.83 0 0
4.968 0 0
5.106 0 0
5.244 0 0
5.382 0 0
5.52 0 12
5.658 0 0
5.796 0 0
5.934 0 0
6.072 43 46
6.21 6711 11323
6.348 91043 116679
6.486 241572 307822
6.624 250588 309749
6.762 105123 139651
6.9 16143 21264
7.038 2521 3648
7.176 1042 1022
7.314 576 910
7.452 482 552
7.59 229 416
7.728 210 227
7.866 120 149
8.004 69 55
8.142 47 0
8.28 26 65
8.418 0 20
8.556 0 0
8.694 0 0
8.832 0 12
8.97 12 38
9.108 0 0
9.246 18 0
9.384 0 0
9.522 0 13
9.66 0 0
9.798 0 18
9.936 16 0
10.074 12 0
10.212 0 0
10.35 12 0
10.488 0 0
10.626 0 23
10.764 0 0
10.902 0 0
11.04 20 0
11.178 0 0
11.316 0 0
11.454 0 0
11.592 0 0
11.73 0 12
11.868 14 12
12.006 0 0
12.144 0 0
12.282 0 0
12.42 0 0
12.558 0 12
12.696 0 0
12.834 0 0
12.972 12 0
13.11 0 0
13.248 0 0
13.386 0 18
13.524 0 0
13.662 12 0
13.8 12 0
13.938 13 0
14.076 0 0
14.214 0 0
14.352 0 0
14.49 0 0
14.628 24 0
14.766 0 15
14.904 0 16
15.042 0 12
15.18 12 0
15.318 0 12
15.456 0 0
15.594 0 0
15.732 14 13
15.87 0 23
16.008 0 0
16.146 0 0
16.284 0 16
16.422 0 12
16.56 0 0
16.698 0 0
16.836 0 0
16.974 0 13
17.112 0 0
17.25 0 0
17.388 16 0
17.526 0 12
17.664 0 0
17.802 0 0
17.94 0 12
18.078 0 0
18.216 0 0
18.354 0 19
18.492 0 0
18.63 0 0
18.768 0 12
18.906 0 0
19.044 0 12
19.182 0 12
19.32 0 0
19.458 0 0
19.596 12 24
19.734 0 0
19.872 0 0
20.01 0 0
20.148 0 0
20.286 0 0
20.424 0 12
20.562 12 0
20.7 0 0
20.838 0 0
20.976 0 0
21.114 0 0
21.252 0 0
21.39 0 12
21.528 12 12
21.666 0 0
21.804 12 0
21.942 0 0
22.08 0 0
22.218 0 0
22.356 0 12
22.494 0 0
22.632 12 0
22.77 0 0
22.908 0 0
23.046 12 0
23.184 0 0
23.322 12 0
23.46 0 0
23.598 13 16
23.736 24 17
23.874 0 0
24.012 12 0
24.15 0 0
24.288 0 0
24.426 12 0
24.564 0 0
24.702 0 0
24.84 0 0
24.978 0 0
25.116 0 0
25.254 0 0
25.392 14 12
25.53 25 0
25.668 0 12
25.806 0 0
25.944 0 15
26.082 0 0
26.22 12 0
26.358 0 0
26.496 0 0
26.634 0 0
26.772 27 0
26.91 0 12
27.048 0 22
27.186 0 0
27.324 0 0
27.462 0 0
然后我有以下代码
import pandas as pd
import numpy as np
first_y= np.array(firt_df.iloc[:,1:])
second_y= np.array(second_df.iloc[:,1:])
#dot product
dot_product_both=np.dot(first_y, second_y)
由于第二列和第三列是我要处理的值,因此我以这种方式读取了first_y和second_y。 但我收到如下错误消息。
shapes (200,42) and (200,42) not aligned: 42 (dim 1) != 200 (dim 0)
我认为我的数据集具有相同的形状。我不确定是什么导致了此问题。
编辑:原始数据集有两列,但我添加了数据的更多部分。
答案 0 :(得分:1)
由于第二列是我要处理的值,因此我读取了 那样是first_y和second_y。
事实并非如此,您已经阅读了第二列,如from kivy.app import App
from kivy.clock import Clock
from kivy.factory import Factory
from kivy.graphics import RenderContext
from kivy.properties import StringProperty
from kivy.uix.widget import Widget
import kivy.core.window
shader = '''
$HEADER$
uniform vec2 resolution;
void main(void)
{
vec2 position = (gl_FragCoord.xy / resolution.xy);
float color = 0.0;
color += position.y / position.x;
if(color < 0.2) { color = 0.2; }
vec3 output_color = vec3(color * 1.5, color, color * 2.0);
gl_FragColor = vec4(output_color, 1.0);
}
'''
shader2 = '''
$HEADER$
uniform vec2 resolution;
void main(void)
{
vec2 position = (gl_FragCoord.xy / resolution.xy);
float color = 0.0;
color += position.y / position.x;
if(color < 0.2) { color = 0.2; }
vec3 output_color = vec3(color * 1.5, color * 2.0, color);
gl_FragColor = vec4(output_color, 1.0);
}
'''
class ShaderWidget(Widget):
fs = StringProperty(None)
def __init__(self, **kwargs):
self.canvas = RenderContext(use_parent_projection=True)
super(ShaderWidget, self).__init__(**kwargs)
self.canvas['time'] = Clock.get_boottime()
Clock.schedule_interval(self.update_glsl, 1 / 60.)
def update_glsl(self, *largs):
self.canvas['time'] = Clock.get_boottime()
self.canvas['resolution'] = [float(v) for v in self.size]
def on_fs(self, instance, value):
shader = self.canvas.shader
shader.fs = value
shader2 = self.canvas.shader
shader2.fs = value
class TestApp(App):
def build(self):
main_widget = Factory.MainWidget()
main_widget.mini.fs = shader
main_widget.mini2.fs = shader2
return main_widget
TestApp().run()
中的第二个冒号所示。相反,只需选择第二列。您也可以使用pd.Series.values
而不是显式调用firt_df.iloc[:, 1:]
:
np.array
约定对于Python列表和NumPy数组是通用的。