コード例 #1
0
 def _to_ndarray(java_tensor: JavaObject) -> Any:
     if (java_tensor.getRank() == 0):
         return np.array(java_tensor.scalar())
     else:
         return Tensor.__get_ndarray_from_tensor(java_tensor).reshape(java_tensor.getShape())
コード例 #2
0
ファイル: type_conversion.py プロジェクト: wwjiang007/Alink
def j_tensor_wrapper_to_np_array(j_obj: JavaObject):
    buffer, dtype_str, shape = j_obj.getBytes(), j_obj.getDtypeStr(
    ), j_obj.getShape()
    arr = np.frombuffer(buffer, dtype=dtype_str).reshape(shape)
    return arr
コード例 #3
0
 def _to_ndarray(java_tensor: JavaObject) -> numpy_types:
     if java_tensor.getRank() == 0:
         return np.array(java_tensor.scalar())
     else:
         return np.array(list(java_tensor.asFlatArray())).reshape(
             java_tensor.getShape())
コード例 #4
0
 def from_java(cls, java_tensor_info: JavaObject) -> "TensorInfo":
     shape = list(java_tensor_info.getShape())
     type = java_gateway.get_field(java_tensor_info, "type").toString()
     return cls(shape, type)