code: def array(val, dtype=None):
      if _torch.is_tensor(val):
          if dtype is None or val.dtype == dtype:
              return val.clone()
  
          return cast(val, dtype=dtype)
  
      if isinstance(val, _np.ndarray):
          tensor = from_numpy(val)
          if dtype is not None and tensor.dtype != dtype:
              tensor = cast(tensor, dtype=dtype)
  
          return tensor
  
      if isinstance(val, (list, tuple)) and len(val):
          tensors = [array(tensor, dtype=dtype) for tensor in val]
          return _torch.stack(tensors)
  
      return _torch.tensor(val, dtype=dtype)
  
imports: import numpy
  import torch
label_desc: Use image node_id 2 for calling a global function with example usage: array(val, dtype) and returns: _torch, cast, tensor, _torch, val