YouTip LogoYouTip

Pytorch Torch Ref

The PyTorch package contains data structures for multidimensional tensors and defines mathematical operations that are performed on these tensors. In addition, it provides many utility tools for efficiently serializing tensors and arbitrary types of data, as well as other useful tools. It also has a CUDA version that allows you to run tensor computations on NVIDIA GPUs with compute capability >= 3.0. ## PyTorch torch API Manual ### **Tensors Type Checking** | Function | Description | | --- | --- | | `torch.is_tensor(obj)` | Check if `obj` is a PyTorch tensor. | | `torch.is_storage(obj)` | Check if `obj` is a PyTorch storage object. | | `torch.is_complex(input)` | Check if the `input` data type is a complex data type. | | `torch.is_conj(input)` | Check if `input` is a conjugate tensor. | | `torch.is_floating_point(input)` | Check if the `input` data type is a floating point data type. | | `torch.is_nonzero(input)` | Check if `input` is a non-zero single-element tensor. | | `torch.set_default_dtype(d)` | Set the default floating point data type to `d`. | | `torch.get_default_dtype()` | Get the current default floating point `torch.dtype`. | | `torch.set_default_device(device)` | Set the default device for `torch.Tensor` allocation to `device`. | | `torch.get_default_device()` | Get the default device for `torch.Tensor` allocation. | | `torch.set_default_tensor_type(tensor_type)` | Set the default tensor type to `tensor_type`. | | `torch.numel(input)` | Return the total number of elements in the `input` tensor. | | `torch.set_printoptions(...)` | Set tensor printing options. | * * * ### **Tensor Creation** | Function | Description | | --- | --- | | `torch.tensor(data, dtype, device, requires_grad)` | Create a tensor from data, copy the data, no automatic gradient history. | | `torch.as_tensor(data, dtype, device)` | Convert data to a tensor, share data and retain automatic gradient history. | | `torch.asarray(data, dtype, device)` | Convert data to a tensor array. | | `torch.from_numpy(ndarray)` | Create a tensor from NumPy array (shared memory). | | `torch.from_dlpack(ext_tensor)` | Create a PyTorch tensor from a dlpack tensor. | | `torch.frombuffer(buffer, dtype, count, offset)` | Create a 1D tensor from buffer. | | `torch.zeros(*size, dtype, device, requires_grad)` | Create a tensor filled with zeros. | | `torch.zeros_like(input, dtype, device, requires_grad)` | Create a tensor filled with zeros with the same shape as input. | | `torch.ones(*size, dtype, device, requires_grad)` | Create a tensor filled with ones. | | `torch.ones_like(input, dtype, device, requires_grad)` | Create a tensor filled with ones with the same shape as input. | | `torch.empty(*size, dtype, device, requires_grad)` | Create an uninitialized tensor. | | `torch.empty_like(input, dtype, device, requires_grad)` | Create an uninitialized tensor with the same shape as input. | | `torch.empty_strided(size, stride, dtype, device)` | Create an uninitialized tensor with specified strides. | | `torch.arange(start, end, step, dtype, device, requires_grad)` | Create a tensor with arithmetic sequence. | | `torch.range(start, end, step, dtype, device, requires_grad)` | Create a tensor with arithmetic sequence including end value. | | `torch.linspace(start, end, steps, dtype, device, requires_grad)` | Create a tensor with evenly spaced sequence. | | `torch.logspace(start, end, steps, base, dtype, device, requires_grad)` | Create a tensor with logarithmically spaced sequence. | | `torch.eye(n, m, dtype, device, requires_grad)` | Create an identity matrix. | | `torch.full(size, fill_value, dtype, device, requires_grad)` | Create a tensor filled with specified value. | | `torch.full_like(input, fill_value, dtype, device, requires_grad)` | Create a tensor filled with specified value with the same shape as input. | | `torch.rand(*size, dtype, device, requires_grad)` | Create a uniformly distributed random tensor (range [0, 1)). | | `torch.rand_like(input
← React Creact First AppPandas Index Object β†’