Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.numpy()函数的作用是什么?_Numpy_Tensorflow_Pytorch - Fatal编程技术网

.numpy()函数的作用是什么?

.numpy()函数的作用是什么?,numpy,tensorflow,pytorch,Numpy,Tensorflow,Pytorch,我试着在网上搜索文档,但找不到任何答案。.numpy()函数做什么?给出的示例代码是: y_true = [] for X_batch, y_batch in mnist_test: y_true.append(y_batch.numpy()[0].tolist()) 在Pytorch和Tensorflow中,.numpy()方法非常简单。它将tensor对象转换为numpy.ndarray对象。这意味着转换后的张量现在将在CPU上处理。如果在理解某个PyTorch函数时遇到问题,可以

我试着在网上搜索文档,但找不到任何答案。
.numpy()
函数做什么?给出的示例代码是:

y_true = []
for X_batch, y_batch in mnist_test:
    y_true.append(y_batch.numpy()[0].tolist())

在Pytorch和Tensorflow中,
.numpy()
方法非常简单。它将
tensor
对象转换为
numpy.ndarray
对象。这意味着转换后的张量现在将在CPU上处理。

如果在理解某个PyTorch函数时遇到问题,可以询问
帮助()

输出:

此函数是从torch.Tensor到numpy数组的转换

import torch
t = torch.tensor([1,2,3])
help(t.numpy)
Help on built-in function numpy:

numpy(...) method of torch.Tensor instance
    numpy() -> numpy.ndarray
    
    Returns :attr:`self` tensor as a NumPy :class:`ndarray`. This tensor and the
    returned :class:`ndarray` share the same underlying storage. Changes to
    :attr:`self` tensor will be reflected in the :class:`ndarray` and vice versa.