У меня есть этот код Matlab, я пытался преобразовать его в Python, но
t = [(3 * pi / 2) * (1 + 2 * rand(ceil(n / 2), 1) * .4); (3 * pi / 2) * (1 + 2 * (rand(floor(n / 2),
1) * .4 + .6))];
height = 30 * rand(n, 1);
X = [t .* cos(t) height t .* sin(t)] + noise * randn(n, 3);
labels = uint8(t);
%labels = rem(sum([round(t / 2) round(height / 12)], 2), 2);
моя попытка для кода python -
# -*- coding: utf-8 -*-
import numpy as np
import pylab as pl
# generate the swiss roll
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import math
n_samples, n_features = 5000, 3
n_turns, radius = 1.2, 1.0
rng = np.random.RandomState(0)
pi=np.random.uniform(0,1,n_samples)
qi=np.random.uniform(0,1,n_samples)
ranceil = np.random.uniform(0,1,math.ceil(n_samples/2))
ranfloor = np.random.uniform(0,1,math.floor(n_samples/2))
t1 =(3*np.pi/2)*(1+(2*ranceil*0.4))
t2 = (3*np.pi/2)*(1+(2* ranfloor * 0.4 + 0.6))
s= [[(3*np.pi/2)*(1+(2*ranceil*0.4)),(3*np.pi/2)* (1+(2* ranfloor * 0.4 + 0.6))]]
t = [[t1,t2]]
#t =np.random.uniform(t1,t2,n_samples)
#t = rng.uniform(t1, t2, size=n_samples)
X = radius = t * np.cos(t)
Y = radius = t * np.sin(t)
Z =30* qi
labels = np.uint8(t)
labels = np.remainder(sum([round(t / 2) * round(Z / 12)], 2), 2)
# rotate and plot original data
sp = pl.subplot(211)
sp.scatter(X, Y, c='g', cmap=plt.cm.rainbow)
sp.set_title("Original data")
fig = plt.figure(figsize=(7,7))
ax = fig.add_subplot(111, projection='3d')
ax.scatter(X, Y, Z , c=labels, cmap=plt.cm.rainbow)
plt.title('Swiss Roll in 3D')
plt.show()
Я получил это ошибка в
labels = np.remainder(sum([round(t / 2) * round(Z / 12)], 2), 2)
TypeError: unsupported operand type(s) for /: 'list' and 'int'
Не знаю как исправить проблему t