类似下面这种运算:
[1,2,3,4,5]
+
[2,1,2,1,3]
-
[0,1,3,0,2]
=
[3,2,2,5,6]
在 Python 中,有 numpy 可以支持,不知道 Java 中有没有类似的 Library 。
加法
>>> a=numpy.array([2,4,5])
>>> b=numpy.array([1,1,1])
>>> a+b
array([3, 5, 6])
乘法
>>> a*b
array([2, 4, 5])
![]() |
1
xiaopanzi 227 天前
如果只是简单的向量计算,自己简单封装一个?当然,如果对性能有要求,需要 SIMD 。
|
![]() |
2
debuggerx 227 天前
Java 不支持用户定义的运算符重载
|
![]() |
3
hanhuoer 227 天前 via iPhone
stream
|
4
thinkershare 227 天前
C#有类似 numpy 的 NumSharp, Java 运算符重载和自定义值类型的限制,导致写出来也不会多简洁直观。C#如果未来添加对 Slice 完全支持,C#应该可以写出和 numpy 一模一样的代码。
|
5
jeesk 227 天前
|
6
WispZhan 227 天前 via Android
|
7
shishiyi 227 天前
据我所知,jdk11 的 stream 没有直接方法实现该方式,但是 spring 的 Reactor 中 zip 方法就是干这种事情的
|
8
XXWHCA 227 天前
2 楼已经回复你了,java 不支持运算符重载,只能通过封装工具方法来实现
|
9
shishiyi 227 天前 ![]() public static void main(String[] args) {
Flux.zip(Flux.just(1,2,3), Flux.just(0, 1, 1)) .map(tuple -> tuple.getT1() + tuple.getT2()) .subscribe(System.out::println); } 打印结果:1 ,3 ,4 |
10
ql562482472 227 天前
这不是矩阵运算吗 apache-common-math
|
11
impossibleshen 227 天前
apache-common-math 或者 apache-common-math3 找找
|
12
aguesuka 227 天前 ![]() vector api https://openjdk.org/jeps/338 正在孵化中
|
13
knives 227 天前
https://www.hipparchus.org/
Hipparchus: a mathematics Library Hipparchus is a library of lightweight, self-contained mathematics and statistics components addressing the most common problems not available in the Java programming language. |
![]() |
15
learningman 226 天前
Java 还在 s1.equals(s2)呢。。。
|
16
buliugu 218 天前
DJL 的 NDArray ,几乎相当于 NumPy
|