Python:语法错误,无效语法,数组编辑



我正在尝试实现以下代码,但在代码的最后一行中继续收到语法错误。但是我找不到错误。在我看来,它与以前的代码完全相同。非常感谢您的任何帮助!

import numpy as np
import matplotlib.pyplot as plt
N=100
D=2
X=np.random.randn(N,D)
#Center first 50 points at (-2,-2)'
X[:50,:] =X[:50,:] - 2 * np.ones((50,D))
#Center last 50 points at 2,2
X=[50:,:]=X[50:,:] + 2 * np.ones((50,D))

您在最后一行中有一个" ="。

X[50:,:]=X[50:,:] + 2 * np.ones((50,D))

尝试一下:

import numpy as np
import matplotlib.pyplot as plt
N=100
D=2
X=np.random.randn(N,D)
#Center first 50 points at (-2,-2)'
X[:50,:] =X[:50,:] - 2 * np.ones((50,D))
# #Center last 50 points at 2,2
X[50:,:]=X[50:,:] + 2 * np.ones((50,D))

最新更新