我的代码段如下:
data,l = make_moons(100000)
s = np.random.permutation(100000);
temp1 = data[s[0:200],:] # Random Sampling of 200 columns
temp2 = cdist(data,temp1) # Pairwise distance between two sets of observations
C = np.exp(-temp2/sig)
W = C[s[0:200],:]
其中make_moons定义为:
from math import pi
def make_moons(n):
"""Create a 'two moons' dataset with n feature vectors,
and 2 features per vector."""
assert n%2==0, 'n must be even'
# create upper moon
theta = np.linspace(-pi / 2, pi / 2, n/2)
# create lower moon
x = np.r_[np.sin(theta) - pi / 4, np.sin(theta)]
y = np.r_[np.cos(theta), -np.cos(theta) + .5]
data = np.c_[x, y]
# Add some noise
data = data + 0.03 * np.random.standard_normal(data.shape)
# create labels
labels = np.r_[np.ones((n//2, 1)), -np.ones((n//2, 1))]
labels = labels.ravel().astype(np.int32)
return data,labels
我想对字幕警告有一些了解。如我所见,数组是浮点型的,但为什么将它们解释为(或需要为)整数?