E:\Eprogramfiles\Anaconda3\lib\site-packages\torch\_tensor.py in __array__(self, dtype)

676 return handle_torch_function(Tensor.__array__, (self,), self, dtype=dtype)

677 if dtype is None:

--> 678 return self.numpy()

679 else:

680 return self.numpy().astype(dtype, copy=False)

RuntimeError: Numpy is not available====================E:\Eprogramfiles\Anaconda3\Scripts>pip show tensorflowName: tensorflowVersion: 2.4.1Summary: TensorFlow is an open source machine learning framework for everyone.Home-page: https://www.tensorflow.org/Author: Google Inc.Author-email: packages@tensorflow.orgLicense: Apache 2.0Location: e:\eprogramfiles\anaconda3\lib\site-packagesRequires: grpcio, absl-py, gast, h5py, six, opt-einsum, wheel, flatbuffers, wrapt, google-pasta, astunparse, protobuf, termcolor, numpy, keras-preprocessing, typing-extensions, tensorboard, tensorflow-estimatorRequired-by:E:\Eprogramfiles\Anaconda3\Scripts>pip show tensorflow-gpuWARNING: Package(s) not found: tensorflow-gpuE:\Eprogramfiles\Anaconda3\Scripts>pip show tensorflow-cpuWARNING: Package(s) not found: tensorflow-cpuE:\Eprogramfiles\Anaconda3\Scripts>====================================    def __array__(self, dtype=None):        if has_torch_function_unary(self):            return handle_torch_function(Tensor.__array__, (self,), self, dtype=dtype)        if dtype is None:            return self.numpy()        else:            return self.numpy().astype(dtype, copy=False)

====================================

x = torch.randn(1, requires_grad=True)x.numpy()# > RuntimeError: Can't call numpy() on Tensor that requires grad. Use tensor.detach().numpy() instead.print(x.detach().numpy())# > array([-0.13592759], dtype=float32)

====================================

查看原文