# Tensor repeat for image patches

I have a batch of 20 flattened tensors representing 256X256 images. >>> imgs.shape (20, 65536) Each image was split into 32×32 patches (a total of 64 patches per image). I have calculated a score for each patch and got a vector with the shape of (20,64) I would like to multiply each pixel with the… Read More Tensor repeat for image patches

# Check if tensor is in list

I can do the following with a single int to retrieve a bool tensor: import torch a = torch.tensor([1,2,3]) a != 2 #tensor([ True, False, True]) Can I do the same with a list in plain pytorch? I.e.: import torch a = torch.tensor([1,2,3]) a not in [2,3] #tensor([ True, False, False]) Thanks a lot for… Read More Check if tensor is in list

# Shuffling two 2D tensors in PyTorch and maintaining same order correlation

Is it possible to shuffle two 2D tensors in PyTorch by their rows, but maintain the same order for both? I know you can shuffle a 2D tensor by rows with the following code: a=a[torch.randperm(a.size()[0])] To elaborate: If I had 2 tensors a = torch.tensor([[1, 1, 1, 1, 1], [2, 2, 2, 2, 2], [3,… Read More Shuffling two 2D tensors in PyTorch and maintaining same order correlation

# numpy complicated manipulation of matrix multiplication

I want to multiply a 3D tensor with a 2D tensor and get a 2D tensor as result. The way I envision this to be done is rather strange, so I ask for your help. The 3D tensor, for when we fix the value of the first dimension to some integer within range(3D_tensor.shape[0]), is a… Read More numpy complicated manipulation of matrix multiplication

# Matrix by Vector multiplication using numpy dot product

I have a matrix m = np.array([[3,4], [5,6], [7,5]]) and a vector v = np.array([1,2]) and these two tensors can be multiplied. For multiplication of the above two tensors, no. of columns of m must be equal to no. of rows of v The shapes of m and v are (3,2) and (2,) respectively. How… Read More Matrix by Vector multiplication using numpy dot product

# How to perform torch.meshgrid over multiple tensors parallely

Let’s say we have a tensor x of size [60,9] and a tensor y of size [60,9] Is it possible to do an operation like xx,yy = torch.meshgrid(x,y) such that xx and yy is of size [60,9,9] and xx[i,:,:], yy[i,:,:] is basically torch.meshgrid(x[i],y[i]) The built-in torch.meshgrid operation only accepts 1d tensors, is it possible to… Read More How to perform torch.meshgrid over multiple tensors parallely

# Why is this requests get not working with this url

If i run this Python code my program just hangs up. (I don`t get any error.) import requests url = "https://raw.githubusercontent.com/tensorflow/docs/master/site/en/tutorials/generative/dcgan.ipynb&quot; r = requests.get(url) But this works perfectly fine as expected. import requests url = "https://stackoverflow.com&quot; r = requests.get(url) Using curl to get the github file worked also fine. curl https://raw.githubusercontent.com/tensorflow/docs/master/site/en/tutorials/generative/dcgan.ipynb So can you reproduce… Read More Why is this requests get not working with this url

# How can I Get, Edit and Set Gradient Matrix in Training of Keras Model?

I am creating a sparse neural network as described in the image below. Keras only provides a dense layer and we can’t choose how many neurons we want to be connected to the previous layer. For implementing this using Keras, I am trying to implement the following approach: 1- Get the Gradient Matrix of each… Read More How can I Get, Edit and Set Gradient Matrix in Training of Keras Model?

# Understanding broadcasting and arithmetic operations on different dimension tensors

I’m currently working on computing various similarity metrics between vectors such as cosine similarity, euclidean distance, mahalanobis distance, etc. As I’m working with vectors that can be very large, I need compute time to be minimal. I’m struggling to understand how to work with vectors of different dimensions (they, do, however, share one dimension) and… Read More Understanding broadcasting and arithmetic operations on different dimension tensors