我的清单有
a = [1,2,3,4,2,7,3,5,6,7]
b = [1,2,3,1,2,5,6,2,6,7]
Run Code Online (Sandbox Code Playgroud)
我需要数一下a[i]==b[i]。
对于以上示例,答案应为
6
Run Code Online (Sandbox Code Playgroud)
答案的详细说明是
a[0]==b[0] (1==1)
a[1]==b[1] (2==2)
a[2]==b[0] (3==3)
a[4]==b[4] (2==2)
a[8]==b[8] (6==6)
a[9]==b[9] (7==7)
Run Code Online (Sandbox Code Playgroud) 如何将 B 列转换为 python 中的转换矩阵?
矩阵的大小为 19,这是 B 列中的唯一值。数据集中共有 432 行。
time A B
2017-10-26 09:00:00 36 816
2017-10-26 10:45:00 43 816
2017-10-26 12:30:00 50 998
2017-10-26 12:45:00 51 750
2017-10-26 13:00:00 52 998
2017-10-26 13:15:00 53 998
2017-10-26 13:30:00 54 998
2017-10-26 14:00:00 56 998
2017-10-26 14:15:00 57 834
2017-10-26 14:30:00 58 1285
2017-10-26 14:45:00 59 1288
2017-10-26 23:45:00 95 1285
2017-10-27 03:00:00 12 1285
2017-10-27 03:30:00 14 1285
...
2017-11-02 14:00:00 56 998
2017-11-02 14:15:00 57 998
2017-11-02 …Run Code Online (Sandbox Code Playgroud) 我有大小为A (1, 1, 59)和B的数组(1, 95, 59)。我想连接数组。数组的大小应为(1, 96, 59)。
np.concatenate((A, B),axis =0)
Run Code Online (Sandbox Code Playgroud)
不起作用 错误是ValueError: all the input array dimensions except for the concatenation axis must match exactly