write down matlab command lines into python

4 visualizzazioni (ultimi 30 giorni)
I am trying to write small part of command lines into python as I am still new and not sure if I am able to do so or not,
clc
z=4;
nu_z=1;
t_MF = [0.1,.12,.2]
t_ID = [1,2,1,1]
x = z*nu_z;
r = 0;
p = zeros(1,x);
for i = 1:z
for j = 1:nu_z
p(r+j) = t(D(i))/nu_z;
end
r = r+nu_z;
end
I tried with python as the following but I got the following error:
I got the following error: IndexError: index 8 is out of bounds for axis 0 with size 8
import numpy as np
z = 4
nu_z = 2
x = z*nu_z
r = 0
t = np.array([0.1,.12,.2])
D = np.array([0,1,0,0])
p = np.zeros((1,x))
for i in range(z):
for j in range(nu_z):
print(j)
p[r+j] = t[D[i]]/nu_z
r = r+nu_z
  4 Commenti
Walter Roberson
Walter Roberson il 9 Ott 2021
I have rarely used python, so I am not certain, but I think it would be
import numpy as np
z = 4
nu_z = 2
x = z*nu_z
r = 0
t = np.array([0.1,.12,.2])
D = np.array([0,1,0,0])
p = np.zeros((1,x))
for i in range(z):
for j in range(nu_z):
print(j)
p[r+j] = t[D[i]]/nu_z
r = r+nu_z
Mark Sc
Mark Sc il 9 Ott 2021
it's correct,
you saved me
thank you so much
How could I accept your answer

Accedi per commentare.

Risposta accettata

Walter Roberson
Walter Roberson il 10 Ott 2021
I have rarely used python, so I am not certain, but I think it would be
import numpy as np
z = 4
nu_z = 2
x = z*nu_z
r = 0
t = np.array([0.1,.12,.2])
D = np.array([0,1,0,0])
p = np.zeros((1,x))
for i in range(z):
for j in range(nu_z):
print(j)
p[r+j] = t[D[i]]/nu_z
r = r+nu_z

Più risposte (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by