Repository: pgmpy/pgmpy

Issue:
ValueError using BayesianEstimation with pseudo_counts after updating to 0.1.14
### ValueError using BayesianEstimation with pseudo_counts after updating to 0.1.14
Passing pseudo_counts to BayesianEstimator.estimate_cpd() leads to an ValueError: 

> ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

### Your environment
* pgmpy 0.1.14, numpy 1.20.2, pandas 1.2.4
* Python 3.8.0
* Operating System: Ubuntu 20.04

### Steps to reproduce
Minimal reproducible code:

> 
> import numpy as np
> import pandas as pd
> import pgmpy.estimators
> import pgmpy.models
> 
> \# a small BayesianModel with one edge, x->y
> edges = [("x", "y")]
> \# assume x and y are categorical, each being either "a" or "b"
> state_names = {"x": ["a", "b"], "y": ["a", "b"]}
> 
> model = pgmpy.models.BayesianModel(edges)
> 
> \# create a DataFrame of x and y observations
> data = pd.DataFrame(
>     [["a", "b"], ["a", "a"], ["a", "b"], ["b", "a"]], columns=["x", "y"]
> )
> 
> \# assign some pseudo_counts
> pseudo_counts_x = np.array([[0], [0]])
> pseudo_counts_y = np.array([[1, 2], [1, 3]])
> pseudo_counts = {"x": pseudo_counts_x, "y": pseudo_counts_y}
> 
> \# use a bayesian estimation with the pseudo_counts provided
> model.fit(
>     data,
>     state_names=state_names,
>     estimator=pgmpy.estimators.BayesianEstimator,
>     prior_type="dirichlet",
>     pseudo_counts=pseudo_counts,
> )


### Expected behaviour
Bayesian Estimation should assign the pseudo_counts to the CPD

(probably the "sanity check" in line https://github.com/pgmpy/pgmpy/blob/afdcf6dfed299517345113298a67c7be23cbd557/pgmpy/estimators/BayesianEstimator.py#L155 should be evaluated to False, as I am passing non-empty pseudo_counts and prior_type="dirichlet" ) 

### Actual behaviour
A ValueError ("The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()") is raised as 
Line https://github.com/pgmpy/pgmpy/blob/afdcf6dfed299517345113298a67c7be23cbd557/pgmpy/estimators/BayesianEstimator.py#L155 leads to a ValueError as 

> (pseudo_counts and pseudo_counts != [] )

 is probably being evaluated as 

> np.array([[1, 2], [1, 3]]) and True


### Next Steps:
I would be happy to provide a bugfix PR if this is desired


Discussion:

Patch:
diff --git a/pgmpy/estimators/BayesianEstimator.py b/pgmpy/estimators/BayesianEstimator.py
index ba52255d..8af808ca 100644
--- a/pgmpy/estimators/BayesianEstimator.py
+++ b/pgmpy/estimators/BayesianEstimator.py
@@ -161,7 +161,9 @@ class BayesianEstimator(ParameterEstimator):
         prior_type = prior_type.lower()
 
         # Throw a warning if pseudo_count is specified without prior_type=dirichlet
-        if (pseudo_counts and pseudo_counts != []) and (prior_type != "dirichlet"):
+        #     cast to np.array first to use the array.size attribute, which returns 0 also for [[],[]]
+        #     (where len([[],[]]) evaluates to 2)
+        if np.array(pseudo_counts).size > 0 and (prior_type != "dirichlet"):
             warn(
                 f"pseudo count specified with {prior_type} prior. It will be ignored, use dirichlet prior for specifying pseudo_counts"
             )


Test patch:
diff --git a/pgmpy/tests/test_estimators/test_BayesianEstimator.py b/pgmpy/tests/test_estimators/test_BayesianEstimator.py
index 29da8a45..bceaf09c 100644
--- a/pgmpy/tests/test_estimators/test_BayesianEstimator.py
+++ b/pgmpy/tests/test_estimators/test_BayesianEstimator.py
@@ -41,6 +41,13 @@ class TestBayesianEstimator(unittest.TestCase):
         )
         self.assertEqual(cpd_A, cpd_A_exp)
 
+        # also test passing pseudo_counts as np.array
+        pseudo_counts = np.array([[0], [1]])
+        cpd_A = self.est1.estimate_cpd(
+            "A", prior_type="dirichlet", pseudo_counts=pseudo_counts
+        )
+        self.assertEqual(cpd_A, cpd_A_exp)
+
         cpd_B = self.est1.estimate_cpd(
             "B", prior_type="dirichlet", pseudo_counts=[[9], [3]]
         )
@@ -63,6 +70,8 @@ class TestBayesianEstimator(unittest.TestCase):
             state_names={"A": [0, 1], "B": [0, 1], "C": [0, 1]},
         )
         self.assertEqual(cpd_C, cpd_C_exp)
+        
+
 
     def test_estimate_cpd_improper_prior(self):
         cpd_C = self.est1.estimate_cpd(