code: def set_tensors_from_ndarray_1d(
      tensors: Union[Iterator[Tensor], Dict[str, Tensor]],
      array: ndarray,
      as_tensor: Callable[[ndarray], Tensor] = torch.as_tensor,
  ) -> None:
      r"""Sets the values of one more tensors based off of a vector of assignments."""
      named_tensors_iter = (
          iter(tensors.items())
          if isinstance(tensors, dict)
          else enumerate(tensors)
      )
      with torch.no_grad():
          index = 0
          for name, tnsr in named_tensors_iter:
              try:
                  size = tnsr.numel()
                  vals = (
                      array[index : index + size]
                      if tnsr.ndim
                      else array[index]
                  )
                  tnsr.copy_(
                      as_tensor(vals).to(tnsr).view(tnsr.shape).to(tnsr)
                  )
                  index += size
              except Exception as e:
                  raise RuntimeError(
                      "`set_tensors_from_ndarray_1d` failed while copying values to "
                      f"tensor {name}; rethrowing original exception."
                  ) from e
  
file_path: botorch/botorch/optim/utils/numpy_utils.py
imports: from __future__ import annotations
  from itertools import tee
  from typing import Callable, Dict, Iterator, Optional, Tuple, Union
  import numpy
  import torch
  from botorch.utils.types import NoneType
  from numpy import ndarray
  from torch import Tensor
label_desc: Use image node_id 3 for calling a global function with example usage: set_tensors_from_ndarray_1d(tensors, array, as_tensor) without return types