Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/291.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 弃用警告:';形状';应使用参数而不是';dims';_Python_Numpy_Gradient Descent - Fatal编程技术网

Python 弃用警告:';形状';应使用参数而不是';dims';

Python 弃用警告:';形状';应使用参数而不是';dims';,python,numpy,gradient-descent,Python,Numpy,Gradient Descent,在我的梯度下降实践中,要在3d图形中绘制MSE,使用以下代码: ij\u min=np.disravel\u index(index=plot\u cost.argmin(),dims=plot\u cost.shape) ij_min是线性回归中的θ0和θ1值,而plot_cost是MSE数组 运行上述命令时,我收到了以下弃用警告: :2:弃用警告:应使用“shape”参数而不是“dims” 我不知道应该用什么来代替dims=plot_cost.shape 有人能帮忙吗?您已经粘贴了两次代码。

在我的梯度下降实践中,要在3d图形中绘制MSE,使用以下代码:

ij\u min=np.disravel\u index(index=plot\u cost.argmin(),dims=plot\u cost.shape)

ij_min是线性回归中的θ0和θ1值,而plot_cost是MSE数组

运行上述命令时,我收到了以下弃用警告:

:2:弃用警告:应使用“shape”参数而不是“dims”

我不知道应该用什么来代替dims=plot_cost.shape


有人能帮忙吗?

您已经粘贴了两次代码。您收到的警告是否与标题相同?=弃用警告:应使用“shape”参数而不是“dims”

弃用警告
表示关键字参数
dims
可用,但不鼓励使用,因为它将在将来的版本中删除。应使用
形状,而不是
dims
。可以这样做:

ij_min=np.dislavel_索引(index=plot_cost.argmin(),shape=plot_cost.shape)
help
函数是检查Python函数和类的公共文档的有用工具

帮助(np.解开索引)

您会注意到,
dims
在我的
numpy
版本1.18.1中不可用。
帮助
输出表明
dims
已在1.16.0版中删除。

谢谢,上面已更正。您对上述问题有何建议?弃用警告通常意味着在接下来的几次迭代中,该功能将不再存在。在您的例子中,unravel方法将使用形状而不是尺寸作为参数。如果你看到文档,它也会有一个例子。让我知道它是否有帮助,如果没有,我会发布一个更详细的答案。
Help on function unravel_index in module numpy:

unravel_index(...)
    unravel_index(indices, shape, order='C')

    Converts a flat index or array of flat indices into a tuple
    of coordinate arrays.

    Parameters
    ----------
    indices : array_like
        An integer array whose elements are indices into the flattened
        version of an array of dimensions ``shape``. Before version 1.6.0,
        this function accepted just one index value.
    shape : tuple of ints
        The shape of the array to use for unraveling ``indices``.

        .. versionchanged:: 1.16.0
            Renamed from ``dims`` to ``shape``.

    order : {'C', 'F'}, optional
        Determines whether the indices should be viewed as indexing in
        row-major (C-style) or column-major (Fortran-style) order.

        .. versionadded:: 1.6.0

    Returns
    -------
    unraveled_coords : tuple of ndarray
        Each array in the tuple has the same shape as the ``indices``
        array.

    See Also
    --------
    ravel_multi_index

    Examples
    --------
    >>> np.unravel_index([22, 41, 37], (7,6))
    (array([3, 6, 6]), array([4, 5, 1]))
    >>> np.unravel_index([31, 41, 13], (7,6), order='F')
    (array([3, 6, 6]), array([4, 5, 1]))

    >>> np.unravel_index(1621, (6,7,8,9))
    (3, 1, 4, 1)