Java 类名:com.alibaba.alink.operator.stream.dataproc.vector.VectorInteractionStreamOp
Python 类名:VectorInteractionStreamOp

功能介绍

对于输入的两个vector中的元素两两相乘,并组成一个新的向量。

参数说明

| 名称 | 中文名称 | 描述 | 类型 | 是否必须? | 取值范围 | 默认值 | | —- | —- | —- | —- | —- | —- | —- |

| outputCol | 输出结果列列名 | 输出结果列列名,必选 | String | ✓ | | |

| selectedCols | 选择的列名 | 计算列对应的列名列表 | String[] | ✓ | 所选列类型为 [DENSE_VECTOR, SPARSE_VECTOR, STRING, VECTOR] | |

| reservedCols | 算法保留列名 | 算法保留列 | String[] | | | null |

| numThreads | 组件多线程线程个数 | 组件多线程线程个数 | Integer | | | 1 |

备注:选择列的数目必须为两列

代码示例

Python 代码

  1. from pyalink.alink import *
  2. import pandas as pd
  3. useLocalEnv(1)
  4. df = pd.DataFrame([
  5. ["$8$1:3,2:4,4:7", "$8$1:3,2:4,4:7"],
  6. ["$8$0:3,5:5", "$8$1:2,2:4,4:7"],
  7. ["$8$2:4,4:5", "$8$1:3,2:3,4:7"]
  8. ])
  9. data = StreamOperator.fromDataframe(df, schemaStr="vec1 string, vec2 string")
  10. vecInter = VectorInteractionStreamOp().setSelectedCols(["vec1","vec2"]).setOutputCol("vec_product")
  11. data.link(vecInter).print()
  12. StreamOperator.execute()

Java 代码

  1. import org.apache.flink.types.Row;
  2. import com.alibaba.alink.operator.stream.StreamOperator;
  3. import com.alibaba.alink.operator.stream.dataproc.vector.VectorInteractionStreamOp;
  4. import com.alibaba.alink.operator.stream.source.MemSourceStreamOp;
  5. import org.junit.Test;
  6. import java.util.Arrays;
  7. import java.util.List;
  8. public class VectorInteractionStreamOpTest {
  9. @Test
  10. public void testVectorInteractionStreamOp() throws Exception {
  11. List <Row> df = Arrays.asList(
  12. Row.of("$8$1:3,2:4,4:7", "$8$1:3,2:4,4:7"),
  13. Row.of("$8$0:3,5:5", "$8$1:2,2:4,4:7"),
  14. Row.of("$8$2:4,4:5", "$8$1:3,2:3,4:7")
  15. );
  16. StreamOperator <?> data = new MemSourceStreamOp(df, "vec1 string, vec2 string");
  17. StreamOperator <?> vecInter = new VectorInteractionStreamOp().setSelectedCols("vec1", "vec2").setOutputCol(
  18. "vec_product");
  19. data.link(vecInter).print();
  20. StreamOperator.execute();
  21. }
  22. }

运行结果

| vec1 | vec2 | vec_product | | —- | —- | —- |

| $8$2:4,4:5 | $8$1:3,2:3,4:7 | $64$10:12.0 12:15.0 18:12.0 20:15.0 34:28.0 36:35.0 |

| $8$1:3,2:4,4:7 | $8$1:3,2:4,4:7 | $64$9:9.0 10:12.0 12:21.0 17:12.0 18:16.0 20:28.0 33:21.0 34:28.0 36:49.0 |

| $8$0:3,5:5 | $8$1:2,2:4,4:7 | $64$8:6.0 13:10.0 16:12.0 21:20.0 32:21.0 37:35.0 |