Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/325.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 弃用警告:类型为<;的对象;类别';浮动'&燃气轮机;无法安全地解释为整数_Python_Numpy_Floating Point_Deprecation Warning - Fatal编程技术网

Python 弃用警告:类型为<;的对象;类别';浮动'&燃气轮机;无法安全地解释为整数

Python 弃用警告:类型为<;的对象;类别';浮动'&燃气轮机;无法安全地解释为整数,python,numpy,floating-point,deprecation-warning,Python,Numpy,Floating Point,Deprecation Warning,我的代码片段如下所示: 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]

我的代码片段如下所示:

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_卫星定义为:

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

我想了解一下标题中的警告。如我所见,数组是浮点型的,但为什么它们被解释(或需要)为整数

theta=np.linspace(-pi/2,pi/2,n/2)
行中,您使用
n/2
作为点数。但是(假设您没有使用Python2)
n/2
是一个浮点数。用
n//2
代替
n/2
@MarkDickinson:Gotcha,谢谢!