对比浮点数矩阵运算测试。
a = np.array([
[
[0.12,0.23,0.34,0.45],
[0.56,0.67,0.78,0.89],
[0.91,0.1011,0.1112,0.1213],
[0.1314,0.1415,0.1516,0.1617]
],
[
[0.12,0.23,0.34,0.45],
[0.56,0.67,0.78,0.89],
[0.91,0.1011,0.1112,0.1213],
[0.1314,0.1415,0.1516,0.1617]
],
[
[0.12,0.23,0.34,0.45],
[0.56,0.67,0.78,0.89],
[0.91,0.1011,0.1112,0.1213],
[0.1314,0.1415,0.1516,0.1617]
],
[
[0.12,0.23,0.34,0.45],
[0.56,0.67,0.78,0.89],
[0.91,0.1011,0.1112,0.1213],
[0.1314,0.1415,0.1516,0.1617]
],
])
b = np.array([
[
[0.12,0.23,0.34,0.45],
[0.56,0.67,0.78,0.89],
[0.91,0.1011,0.1112,0.1213],
[0.1314,0.1415,0.1516,0.1617]
],
[
[0.12,0.23,0.34,0.45],
[0.56,0.67,0.78,0.89],
[0.91,0.1011,0.1112,0.1213],
[0.1314,0.1415,0.1516,0.1617]
],
[
[0.12,0.23,0.34,0.45],
[0.56,0.67,0.78,0.89],
[0.91,0.1011,0.1112,0.1213],
[0.1314,0.1415,0.1516,0.1617]
],
[
[0.12,0.23,0.34,0.45],
[0.56,0.67,0.78,0.89],
[0.91,0.1011,0.1112,0.1213],
[0.1314,0.1415,0.1516,0.1617]
],
])
A: c = a * b
B: c = np.matmul(a,b)
C: c = a @ b
测试下来耗时 A < B < C ???
这是啥情况,原生*运算比 numpy 优化过的速度还快???
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.