6

# Array passed to %s is full of zeros.

Package:
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
---------- """``````
😲  Walkingbet is Android app that pays you real bitcoins for a walking. Withdrawable real money bonus is available now, hurry up! 🚶

1

## 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')
```
Jul 16, 2021