Good day all,
I was trying to do some signal processing in Pytorch. I have written the same code in Tensorflow and it worked, but the one below is not.
Thank you.
import os
import torch
from torch.autograd import Variable
import numpy as np
class Modulator(object):
def __init__(self, mod_type, K):
# Set modulation type
if (mod_type not in ['BPSK', '4PAM']):
raise(Exception('Modulator: Unknown modulation format'))
self.mod_type = mod_type
self.K = K
# Create constellation
if (self.mod_type == 'BPSK'):
self.constellation = np.array([-1.0, 1.0])
self.constellation = torch.from_numpy(self.constellation)
elif (self.mod_type == '4PAM'):
self.constellation = np.array([-3.0, -1.0, 1.0, 3.0])
self.constellation = torch.from_numpy(self.constellation)
self.constellation_size = self.constellation[:,0].shape
# Normalize constellation to unit power and convert to tensor
self.constellation /= torch.sqrt(torch.mean(torch.abs(self.constellation)**2))
self.constellation = torch.Variable(self.constellation, requires_grad = False)
return
def random_indices(self, batch_size=4):
'''Generate random constellation symbol indices'''
indices = torch.FloatTensor(, self.K).uniform_(0,self.constellation_size).int()
return indices
indices = Modulator(‘BPSK’, 10)
When the code is run, the following error is returned:
in
33
34 return indices
—> 35 indices = Modulator(‘BPSK’, 10)
in init(self, mod_type, K)
21 self.constellation = torch.from_numpy(self.constellation)
22
—> 23 self.constellation_size = self.constellation[:,0].shape
24
25 # Normalize constellation to unit power and convert to tensor
IndexError: too many indices for tensor of dimension 1