How to use 'list to tensor' in Python

Every line of 'list to tensor' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
140def __to_ndarray_list(tensors, titles):
141 if not isinstance(tensors, list):
142 tensors = [tensors]
143 titles = [titles]
144 assert len(titles) == len(tensors),\
145 "[visualizer]: {} titles are not enough for {} tensors".format(
146 len(titles), len(tensors))
147 for i in range(len(tensors)):
148 if torch.is_tensor(tensors[i]):
149 tensors[i] = tensors[i].cpu().detach().numpy()
150 return tensors, titles
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

111def _to_tensors(self, ts):
112 x = []
113 y = []
114 for sample in ts:
115 x.append(sample['word'].squeeze())
116 y.append(sample['y'].squeeze())
117 return np.stack(x), np.stack(y)

Related snippets