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

功能介绍

转换张量类型为向量类型。

参数说明

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

| selectedCol | 选中的列名 | 计算列对应的列名 | String | ✓ | 所选列类型为 [DOUBLE_TENSOR, FLOAT_TENSOR, INT_TENSOR, LONG_TENSOR] | |

| convertMethod | 转换方法 | 张量转换为向量的方法,可取 flatten, sum, mean, max, min. | String | | “FLATTEN”, “SUM”, “MEAN”, “MAX”, “MIN” | “FLATTEN” |

| outputCol | 输出结果列 | 输出结果列列名,可选,默认null | String | | | null |

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

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

代码示例

Python 代码

  1. from pyalink.alink import *
  2. import pandas as pd
  3. useLocalEnv(1)
  4. df_data = pd.DataFrame([
  5. ['DOUBLE#6#0.0 0.1 1.0 1.1 2.0 2.1']
  6. ])
  7. stream_data = StreamOperator.fromDataframe(df_data, schemaStr = 'tensor string')
  8. stream_data.link(TensorToVectorStreamOp().setSelectedCol("tensor")).print()
  9. 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.source.MemSourceStreamOp;
  4. import org.junit.Test;
  5. import java.util.Collections;
  6. import java.util.List;
  7. public class TensorToVectorStreamOpTest {
  8. @Test
  9. public void testTensorToVectorStreamOp() throws Exception {
  10. List <Row> data = Collections.singletonList(Row.of("DOUBLE#6#0.0 0.1 1.0 1.1 2.0 2.1"));
  11. MemSourceStreamOp memSourceStreamOp = new MemSourceStreamOp(data, "tensor string");
  12. memSourceStreamOp
  13. .link(
  14. new TensorToVectorStreamOp()
  15. .setSelectedCol("tensor")
  16. )
  17. .print();
  18. StreamOperator.execute();
  19. }
  20. }

运行结果

| tensor | | —- |

| 0.0 0.1 1.0 1.1 2.0 2.1 |