I can't find ConvexHull in scipy.spatial - python

Edit: As far as I can tell it's an issue with the build, I haven't figured out exactly what yet, but I've narrowed it down to that. For anyone reading this, try the suggestion in the marked answer first.
I'm trying to use the ConvexHull function from the scipy library to compute the convex hull for some points, but scipy.spatial.ConvexHull doesn't seem to exist.
The documentation has this as an example:
from scipy.spatial import ConvexHull
points = np.random.rand(30, 2) # 30 random points in 2-D
hull = ConvexHull(points)
I tried to use this example in my project but couldn't get it to work..
I typed in the appropriate import line but ConvexHull was not found, PyCharm underlined the ConvexHull reference in red, and a mouse-hover shows a 'not found' message.
I've found various mentions on SO about different methods that might be required for importing and using parts of scipy, which I've tried and none of them seem to work, including the import line in the docs example.
I'm running Python 3.6 inside a clean PyCharm venv that I've just created. The pip install of scipy worked fine and scipy is appearing when I try to import it, as is spatial... but ConvexHull doesn't seem to exist.
I'm using scipy 1.1.0, and I've tried using the import that a deleted answer provided...
from scipy.spatial.qhull import ConvexHull... but this didn't work.
Alternately, if this won't work then I am willing to use a different library if possible.

https://docs.scipy.org/doc/scipy/reference/generated/scipy.spatial.ConvexHull.html
Did you try
from scipy import spatial
spatial.ConvexHull
In 1.0.1 both of these work
In [2]: spatial.qhull.ConvexHull?
In [3]: spatial.ConvexHull?
Glancing at the github issues, there may be some build issues, involving cython versions, that may prevent building the qhull file.
https://github.com/scipy/scipy/issues/8562 - CI: Appveyor builds fail because it can't import ConvexHull from spatial.qhull
I upgraded to 1.1.0, and had no problem accessing ConvexHull.

Related

Python4Delphi can't import numpy

I was curious about Python4Delphi and installed it and looked through the demos a bit. Now I wanted to install Numpy via CMD with pip this went well without errors. but now when I enter the following code in DEMO01 of Python4Delphi I get an error message. If I enter the same code in python it works. How can i solve this?
How i installed Numpy:
pip install numpy
Example code:
import numpy as np
print(np .__version__)
The error i got:
AttributeError: partially initialized module 'numpy' has no attribute '__version__' (most likely due to a circular import). Did you mean: '_version'?
The versions:
Delphi 11,
Python 3.10.4,
Pip 22.1,
Numpy 1.22.4 and
Win64
if i forgot some information let met know.
Can you check you're using the same versions of python using both methods by checking what this returns...
import sys
for p in sys.path:
print(p)
Carefully compare the output of that little bit of code as it'll point out any obvious differences.
From my experiments if you've got more than one Python on your system things can get weird with Python4Delphi so the above should provide evidence if this is your situation.
Importing numpy should actually cause an exception anyway, just not the one you mention in your question. Importing Numpy in demo01 will trigger a div by zero unless you add a MaskFPUExceptions(True); before you execute the python
If you use an embedded Python things will get even worse for you as you'll need to set some additional paths to import anything. The only way I've found to do this properly ATM is by addending paths to sys.path in a small python stub with paths constructed relative to the embedded root (Lib and Lib/site-packages incidentally)

How to find GLCM matrix in python?

We are using Python 2.7.9.and scikit image library. We are not able to use skimage.feature.greycomatrix because there is no file such as greycomatrix.py in the feature folder. Their documentation seems to be wrong as it says this function is available. We get an error module attribute has no object feature. Is there any other image processing library in Python which will help us achieve this goal?
from skimage.feature import greycomatrix
This works for me, just like the instructions at http://scikit-image.org/docs/dev/auto_examples/plot_glcm.html.
Maybe you just have an old version and need to update scikit-image? Or if it was actually a bug on their behalf they have probably fixed it now.
Which version of scikit-image do you have? That is more relevant for this problem than your Python version. For me:
import skimage
print skimage.__version__
'0.11.2'
So for version 0.11.2 up atleast it should work.
In my case I use the following imports and it works for me.
I say
import skimage.feature as sk
##Then I say
glcm = sk.greycomatrix(img, [1],[0])
This should work fine.

GNU Radio filter design tool (gr_filter_design)

I am having some trouble getting the filter design tool to even start. When starting the application I get
"This example requires a Numerical Python Extension, but
failed to import either NumPy, or numarray, or Numeric.
NumPy is available at http://sourceforge.net/projects/numpy".
I have rebuild GNU Radio a couple of times now, and I am fairly sure that I have every thing installed that is required. I do have numpy installed, and I have tried a couple of versions just to be safe.
Has some one else had this problem?
You are getting this error as
from PyQt4.Qwt5.anynumpy import *
in polezero_plot.py (/usr/lib/python2.7/site-packages/gnuradio/filter) is failing.
Just try replacing
from PyQt4.Qwt5.anynumpy import * ( line no 25)
with
from scipy import zeros
or
from numpy import zeros
If you have a recent version of NumPy installed, you're most likely running into problems because of this line in anynumpy:
from numpy.oldnumeric.compat import *
oldnumeric provided backwards-compatibility support for code written using NumPy's predecessor Numeric, and was removed in NumPy 1.9 which was released at about the time of your question. It looks like the GNU Radio filter design tool simply isn't compatible with NumPy 1.9 right now.
I ran into a similar issue just now, and had to import fftpack from SciPy instead of NumPy. NumPy was still needed for actually generating the filters (removing import numpy would cause gr_filter_design to crash when clicking the "Design" button).
/usr/lib/python3.8/site-packages/gnuradio/filter/filter_design.py:
# import numpy
# from numpy.fft import fftpack
# from scipy import poly1d, signal
import numpy
from scipy import fftpack, poly1d, signal
Versions: Manjaro Linux, numpy 1.18.1, scipy 1.4.1, and gnuradio 3.8.0.0.

Import threshold_yen and threshold_isodata from skimage.filter

I am working with different threshold algorithms from SKimage, and when I go to import certain packages I get an error, but have no problem with others. For example:
from skimage.filter import threshold_adaptive, threshold_isodata
returns the traceback:
ImportError: cannot import name threshold_isodata. I am using python 2.7, and following the documentation found here: http://scikit-image.org/docs/dev/api/skimage.filter.html#skimage.filter.threshold_isodata
Specifically, I'm hoping to use threshold_isodata and threshold_yen. Does anybody have suggestions for how to solve this error? Alternatively, are there other packages that use the same algorithm?
As mentioned in a comment, threshold_isodata is only available in the master repo (i.e. not officially released in v0.9), hence the import error.
It turns out that threshold_yen wasn't properly imported into the filter subpackage in version 0.9. (This has been fixed in master.) Until v0.10 is released, you should import threshold_yen as follows:
from skimage.filter.thresholding import threshold_yen
EDIT: Note that this question and answer are specific to very old versions of scikit-image. The skimage.filter module was renamed skimage.filters in v0.11

How / Where to download Pylab for Python 2.7 on Win32?

I have googled all over, and don't see where to get pylab.
What am I missing?
Thanks!
I believe there are two "versions" of pylab floating around/being referred to.
The first is a part of matplotlib -- you just install matplotlib and do either import pylab or import matplotlib.pyplot as pyplot. (More info on pylab vs pyplot).
The second is described here, and as far as I know, doesn't exist yet. The linked version is simply describing a hypothetical vision of what the existing version of pylab could be. It's also unfortunately the first result when you try googling "pylab", which I suspect is what caused your confusion.
Source: http://matplotlib.1069221.n5.nabble.com/pylab-td23420.html#a23423
You can get it as part of EPD's Canopy distribution.

Categories

Resources