# Error in inversion algorithm for PGI inversion when setting GMM update = True

**URL:** <https://simpeg.discourse.group/t/error-in-inversion-algorithm-for-pgi-inversion-when-setting-gmm-update-true/603>\
**Category:** Potential Fields\
**Created:** [August 21, 2024, 10:32am UTC](https://simpeg.discourse.group/t/error-in-inversion-algorithm-for-pgi-inversion-when-setting-gmm-update-true/603 "2024-08-21T10:32:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mridul](https://avatars.discourse-cdn.com/v4/letter/m/9d8465/32.png) [@Mridul](https://simpeg.discourse.group/u/Mridul)\
**Post date:** [August 21, 2024, 10:32am UTC](https://simpeg.discourse.group/t/error-in-inversion-algorithm-for-pgi-inversion-when-setting-gmm-update-true/603/1 "2024-08-21T10:32:36Z")

</div>

Greetings,  
As a young researcher being in initial days of work, I was working on exploring the PGI inversion of Gravity data.  
I have been stuck to a point where the inversion code interrupts saying:

ValueError Traceback (most recent call last)  
 in \<cell line: 101\>()  
99  
100 # Run the inversion  
 → 101 inverted\_model = inversion\_algo.run(initial\_model)

13 frames  
/usr/local/lib/python3.10/dist-packages/simpeg/utils/pgi\_utils.py in \_check\_weights(self, weights, n\_components, n\_samples)  
220  
221 # check range  
 → 222 if any(np.less(weights, 0.0)) or any(np.greater(weights, 1.0)):  
223 raise ValueError(  
224 "The parameter ‘weights’ should be in the range "

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

I have checked the weights (it sums to a total of 1), and also looked for solutions here and there but nothing works.  
Also when I change the  
update\_gmm=True —\> update\_gmm=False, after this the inversion runs successfully, but the learned GMM after iterations in inversion comes out to be faulty as the GMM peaks doesnt collide with the new peaks generated.

I am hoping to see your response.  
Mridul Chawla

---

<div class="post-metadata">

**Author:** ![santisoler](https://yyz2.discourse-cdn.com/free1/user_avatar/simpeg.discourse.group/santisoler/32/210_2.png) [@santisoler](https://simpeg.discourse.group/u/santisoler)\
**Post date:** [August 28, 2024, 5:10pm UTC](https://simpeg.discourse.group/t/error-in-inversion-algorithm-for-pgi-inversion-when-setting-gmm-update-true/603/2 "2024-08-28T17:10:04Z")

</div>

Hi Mridul. Thanks for reporting this issue.

The reason why the code is failing on you is because in your case the `weights` array that is being passed to `_check_weights` is a 2d array. When running `np.less(weights, 0.0)` we obtain a 2d array of bools, and running `any()` on this array will raise the ValueError you are experiencing.

Luckily we can easily solve that by using Numpy’s `a.any()` method instead of the Python built-in `any()` function.

I’ll open a PR to fix this and to add tests that catches this bug. I’ll post a link to it here once it’s opened.

Thanks again for reporting this issue!
