-1

In my practice on Gradient Descent, to plot the MSE in a 3d Graph, following code is use :

ij_min = np.unravel_index(indices=plot_cost.argmin(), dims=plot_cost.shape)

ij_min are the theta0 and theta1 values in the linear regression while plot_cost is the MSE array.

While running the above command, I got the following deprecation warning :

:2: DeprecationWarning: 'shape' argument should be used instead of 'dims'

I am confused as to what should be used in place of dims=plot_cost.shape.

Can someone help please ?

Sachin
  • 85
  • 9

2 Answers2

0

you have pasted your code twice. Is the warning you are getting same as the title ? = DeprecationWarning: 'shape' argument should be used instead of 'dims'

Bharath
  • 406
  • 2
  • 13
  • Thanks, corrected above. Do you have a suggestion on the above question ? – Sachin Oct 02 '20 at 17:47
  • Deprecation warning would generally mean over next few iterations the functionality would cease to exist. In your case unravel method would use shape instead of dimensions as an argument. If you see the documentation - it would have an example as well. – Bharath Oct 02 '20 at 17:54
  • Let me know if it helps , if it doesnt i will post a more detailed answer. – Bharath Oct 02 '20 at 17:54
0

The DeprecationWarning indicates that the keyword argument dims is available but its use is discouraged because it will be removed in a future version. Instead of dims, shape should be used. This can be done like so:

ij_min = np.unravel_index(indices=plot_cost.argmin(), shape=plot_cost.shape)

The help function is a useful tool for examining the public documentation of Python functions and classes.

help(np.unravel_index)
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)

You'll note that dims is unavailable in my version of numpy, 1.18.1. The help output indicates that dims was removed in version 1.16.0.

Michael Ruth
  • 2,938
  • 1
  • 20
  • 27