class_docstr: A class representing a tensor, which could have arbitrary dimensions.
  A batch of these tensors are padded to the max dimension length in the batch
  for each dimension.
class_docstr_tok: ["A","class","representing","a","tensor",",","which","could","have","arbitrary","dimensions",".","A","batch","of","these","tensors","are","padded","to","the","max","dimension","length","in","the","batch","for","each","dimension","."]
code: def __init__(
      self,
      tensor: Union[torch.Tensor, np.ndarray],
      padding_value: Any = 0.0,
      dtype: Optional[Union[np.dtype, torch.dtype]] = None,
  ) -> None:
      if dtype is not None:
          if isinstance(tensor, np.ndarray):
              tensor = tensor.astype(dtype)
          elif isinstance(tensor, torch.Tensor):
              tensor = tensor.to(dtype)
          else:
              raise ValueError(
                  "Did not recognize the type of `tensor`."
              )
      if isinstance(tensor, np.ndarray):
          tensor = torch.from_numpy(tensor)
  
      self.tensor = tensor.cpu()
      self.padding_value = padding_value
  
file_path: allennlp/allennlp/data/fields/tensor_field.py
imports: from typing import Dict, Any, Union, Optional
  import torch
  import numpy
  from allennlp.data.fields.field import Field
  from allennlp.common.util import JsonDict
label_desc: Use image node_id 1 to create a new TensorField object from inherited base classes: Field with example: obj = TensorField(tensor, padding_value, dtype)