Array passed to %s is full of zeros.
Package:
scikit-learn
47032

Exception Class:
ValueError
Raise code
def _check_init(A, shape, whom):
A = check_array(A)
if np.shape(A) != shape:
raise ValueError('Array with wrong shape passed to %s. Expected %s, '
'but got %s ' % (whom, shape, np.shape(A)))
check_non_negative(A, whom)
if np.max(A) == 0:
raise ValueError('Array passed to %s is full of zeros.' % whom)
def _beta_divergence(X, W, H, beta, square_root=False):
"""Compute the beta-divergence of X and dot(W, H).
Parameters
---------- """
Links to the raise (1)
https://github.com/scikit-learn/scikit-learn/blob/c67518350f91072f9d37ed09c5ef7edf555b6cf6/sklearn/decomposition/_nmf.py#L60Ways to fix
Summary:
This exception is thrown when the _check_init function is called. This function takes in three required parameters: A, shape, and whom. A must be an array that has the same shape as the value passed in for the parameter shape. Then a check is performed to ensure that A has a value larger than 0, if nothing is found then this exception is thrown. So ensure that A has at least one value that is larger than 0.
Code to Reproduce the Error (Wrong):
from sklearn.decomposition._nmf import _check_init
import numpy as np
A = np.zeros((2,2))
shape = (2,2)
_check_init(A, shape, 'whom')
Error Message:
ValueError Traceback (most recent call last)
<ipython-input-2-bb9bec6d8eb8> in <module>()
4 A = np.zeros((2,2))
5 shape = (2,2)
----> 6 _check_init(A, shape, 'whom')
/usr/local/lib/python3.7/dist-packages/sklearn/decomposition/_nmf.py in _check_init(A, shape, whom)
57 check_non_negative(A, whom)
58 if np.max(A) == 0:
---> 59 raise ValueError('Array passed to %s is full of zeros.' % whom)
60
61
ValueError: Array passed to whom is full of zeros.
Working Version (Right):
from sklearn.decomposition._nmf import _check_init
import numpy as np
A = np.ones((2,2))
shape = (2,2)
_check_init(A, shape, 'whom')
Add a possible fix
Please authorize to post fix