Fehler:numpy.narray Objekt nicht aufrufbar

Ich versuche konvertieren von Matlab-code auf Python, aber es gibt einen Fehler, wenn ich konvertieren Sie die folgende Zeile:

Matlab-Code

md(1,index) = (-1)^bits(m);

Python-äquivalent

md[index]=(-1)**bits(m)

Fehler

md[index]=(-1)**bits(m)
TypeError: 'numpy.ndarray' object is not callable

Matlab-Code

fdel=2;
fn=10;

zeta=1/sqrt(2);
spb=100;
npts=2000;
fs=2000;
freq_in = zeros(1,2000);      % initialize input frequency array
phi_in = zeros(1,2000);       % initialize input phase array
t = (0:(npts-1))/fs;            % generate vector of sample times
nsettle = fix(npts/10);         % set settle time as 0.1*npts
tsettle = nsettle/fs;           % set settle time
% 
% %       The following three lines of code generate the arrays of the
% %       input frequency and input phase. 
% 
phin1 = 2*pi*fdel*(t-tsettle);
freq_in = [zeros(1,nsettle),fdel*ones(1,npts-nsettle)];
phi_in = [zeros(1,nsettle),phin1(1,(nsettle+1):npts)];
% 
% %       Generate the QPSK input signal and input signal.
% 
nbits = npts/spb;               % Determine number of bits
md = zeros(1,nbits*spb);
bits = round(rand(1,nbits));
for m=1:nbits

 for n=1:spb
  index = (m-1)*spb + n;
  % error making line
    md(1,index) = (-1)^bits(m);
 end
 end

Python-Code

fdel=2
fn=10
zeta=1/sqrt(2)
spb=100
npts=2000
fs=2000
freq_in=zeros(2000)
phi_in=zeros(2000)
t=(arange(0,npts-1))/fs
nsettle=fix(npts/10)
tsettle=nsettle/fs
phin1=2*pi*fdel*(t-tsettle)
freq_in=array([zeros(nsettle),fdel*ones(npts-nsettle)])
phi_in=array([zeros(nsettle),phin1[nsettle+1:npts]])
nbits=npts/spb

md=zeros(nbits*spb)
bits=around(np.random.uniform((nbits,)))

for m in arange(0,nbits):
    for n in arange(0,spb):
       index=(m-1)*spb+n
       md[index]=(-1)**bits(m)
  • Ich vermute, dass der Fehler bedeutet, dass bits(m) ist nicht eine Funktion, D. H. Sie sollten nicht verwenden Sie Klammern, um ihm den index. Versuchen bits[m] statt.
  • -1: python-debugging-Tipps
  • danke es tatsächlich geholfen...aber jetzt ist seine Angabe index out of bound
Schreibe einen Kommentar