how to calculate poles of a discrete line in python api? - python

Is there any python libs that could calculate poles of a line like [(x1,y1), (x2,y2)...]?
for instance, I have a line consist by 2d points like [[x1,y1],[x2,y2],[x3,y3]...], then I want to calculate the poles of the line, only using python libs. So is there any python lib could do this for me

Hello HOWE,
Python provides many library for the create the any types of the graph.
For example 2d, 3d,... graph etc.
1. NumPy
If you use Math function/expression so first install this library it is provides many easy functionality.
NumPy is the fundamental package for scientific computing with Python. It contains among other things:
a powerful N-dimensional array object
sophisticated (broadcasting) functions
tools for integrating C/C++ and Fortran code
useful linear
algebra, Fourier transform, and random number capabilities
Besides its obvious scientific uses, NumPy can also be used as an efficient multi-dimensional container of generic data. Arbitrary data-types can be defined. This allows NumPy to seamlessly and speedily integrate with a wide variety of databases.
Install this library for go on this link, http://www.numpy.org/
2. Matplotlib
After install this library to create the any types of the graph.
Matplotlib is a Python 2D plotting library which produces publication quality figures in a variety of hardcopy formats and interactive environments across platforms. Matplotlib can be used in Python scripts, the Python and IPython shell, the jupyter notebook, web application servers, and four graphical user interface toolkits.
Install this library for go on this link, https://matplotlib.org/
I hope my answer is helpful.
If any query so comment please.

Related

Why does SciPy require an installation procedure?

I'm trying to wrap my head around the Python ecosystem and parts of it aren't making complete sense to me so far.
I'm coming from the Java world and when I want to make use of, say JUnit, I simply add the JUnit jar to my classpath and that's pretty much it. If I want to be nice to my users I can also easily bunch together all my dependencies into a single jar, so that all that they need to do is install a Java Runtime get a hold of my jar.
Reading through the SciPy installation guide I can't find an explanation for why all this is really necessary. And how is this ever going to work at deployment time? It's like JUnit asked me to install a new JRE just for them.
SciPy has parts written in C that require compilation for the specific platform it's being deployed too.
How can SciPy be fast if it is written in an interpreted language like Python?
Actually, the time-critical loops are usually implemented in C or
Fortran. Much of SciPy is a thin layer of code on top of the
scientific routines that are freely available at
http://www.netlib.org/. Netlib is a huge repository of incredibly
valuable and robust scientific algorithms written in C and Fortran. It
would be silly to rewrite these algorithms and would take years to
debug them. SciPy uses a variety of methods to generate “wrappers”
around these algorithms so that they can be used in Python. Some
wrappers were generated by hand coding them in C. The rest were
generated using either SWIG or f2py. Some of the newer contributions
to SciPy are either written entirely or wrapped with Cython.
Source: http://www.scipy.org/scipylib/faq.html#id12
On Linux, SciPy and NumPy libraries’ official releases are source-code
only. Installing NumPy and SciPy from source is reasonably easy;
However, both packages depend on other software, some of them which
can be challenging to install, or shipped with incompatibilities by
major Linux distributions. Hopefully, you can install NumPy and SciPy
without any software outside the necessary tools to build python
extensions, as most dependencies are optional
Source: http://www.scipy.org/scipylib/building/linux.html

Distributing an interactive matplotlib plot

I have a Python script that generates an interactive matplotlib plot with several sliders and radio buttons using the matplotlib.widgets submodule. I'd like to let others play with the resulting plot without having to install python, scipy, numpy, and matplotlib.
I first tried converting my python script to a stand-alone executable that I could distribute. This turned out to be a nightmare - every package I tried (pyinstaller, py2exe, cx_Freeze) failed for one reason or another. The main issue I had was with integrating various scipy and matplotlib libraries, and I'm now very pessimistic about successfully "freezing" my interactive plot.
My next idea was to see if I could get some interactivity through a web browser. Using an IPython notebook with the third-party package JSAnimation initially seemed very promising (http://nbviewer.ipython.org/github/jakevdp/JSAnimation/blob/master/animation_example.ipynb), but it seems that the package only supports the matplotlib "animate" function. This doesn't quite fit the bill for what I'd like to do, as I have multiple sliders which 1) doesn't seem to be supported by this package, and 2) even if supported, would likely result in too many static figures to pre-render effectively, since any such arrangement would require snapshots for every possible combination of the three variables.
Any ideas for how to get this interactive matplotlib plot to others without requiring them to install Python?

c++ gis/spatial library for higher performance computing

So I am working on setting up an agent-based model that runs over a geographic map--syria in this case. I tried writing it in python, but the performance is rather slow--even after some optimization tricks. I was thinking that I should shift to just writing the model in C++, but I don't know which visualization packages can incorporate maps? I tend to use gnuplot in C++, but I have not been able to find a way to incorporate a gis basemap in that package. I am not sure if this is possible in VTK or any other packages. I would like to find a way to run my model fast in C++ but not lose the geographic information. Any suggestions?
Perhaps this project could be useful to you ?
http://code.google.com/p/vtk-grass-bridge/
If you can handle your GIS data using GRASS, it seems that project can convert it to something VTK can render, all in one C++ application.
So I actually figured out the answer to this problem and am posting the solution for everyone. The best choice if you are using python, is to just use the mayavi and tvtk packages from Enthought. Mayavi is a gui on top of the C++ VTK libraries. And tvtk is actually a wrapper for python access to VTK objects. So this allows a person to use python GIS packages--like pyshp, Shapely, and others to manipulate GIS objects and then write them to robust and fast mayavi for visualization. At the same time, if you want to stick to C++ then you can still just write your code in C++ using gdal or ogr, etc., and then run your visualization in VTK. This seems a lot easier and more intuitive then trying to run through some other packages like GRASS, QGIS, or ArcGIS.
Here is a good example of this toolset in action.
Example
What makes you believe that a C++ implementation of your model will be dramatically faster? I suggest before being concerned with how you will visualize the results you focus first on what causes your python implementation to be slow. Is it that your algorithm won't scale? If you have tried optimization tricks, what tricks were those and why do you believe they did not work?
It all eventually comes down to machine instructions being executed on hardware, whether those instructions started out as python, C++ , or some other language source code. Unless your python was running fully interpreted all the time I don't think you will find that switching languages alone will cause you to have a fundamentally different performance profile. Premature optimization is still something to be avoided.

Numpy analog for Jython [duplicate]

This question already has answers here:
Is there a good NumPy clone for Jython? [closed]
(4 answers)
Closed 9 years ago.
I am considering porting scientific code from Python to Jython and I am interested, whether there exist math libraries
for Jython, which are:
free for commercial use
have convenient matrix syntax designed for Jython - i.e. permit slicing, binary and integer indexing, +-*/ operations like matlab and numpy.
Additional availability of machine learning and statistical routes would be a plus (or easy convertibility of data to some common data format, understood by major Java machine learning libraries).
Thanks in advance for any information about such libraries.
I took on the role of maintaining such a package a while back. It's called jnumeric (available on github and installable via maven).
JNumeric kind of has a weird history though, dating back to the early 2000s. It's never really been functionally equivalent to NumPy (or even numeric, which is what it's actually trying to emulate), and while it was "good enough" for what we were using it for, to use it as the primary number-cruncher in a Java program is probably not a good idea. It was a bad enough idea that we rewrote our application from scratch in Python so that we could use NumPy instead of trying to do vector math in Java. For that reason, jnumeric is undermaintained, and should probably silently fade into non-existence.
I recently noticed a new project pop up on Github, Numpy4J, which may have a brighter future.
While I know it doesn't quite address your question, I am curious why you would want to move to Jython for scientific code. Java does not have the nice number crunching and plotting libraries that Python has. ML libraries like Weka have Python equivalents in scikit-learn. Imaging stuff like ImageJ has an equivalent in scikit-image. Statistical packages exist in pandas and statsmodels. What is your scientific itch that Python does not scratch?
If you want to move to Jython in order to interface with an existing Java library that cannot be easily ported to Python, I would consider JPype rather than Jython.

IPython Pylab Configuration - imshow interpolation

I have been working with IPython for several months now and I think it is one of the best interactive shells I've used. I especially like the built in matplotlib support through pylab.
One issue I have had is that I am working with image analysis and often plot images and other arrays using imshow. When using pure matplotlib, I have the ability to set the default interpolation as nearest using the matplotlibrc file. I have not been able to find such a file for the built in matplotlib in IPython.
Is there a way to configure IPython and Pylab to use nearest interpolation by default instead of bilinear? I have read the IPython documentation regarding configuration and customization and I'm not sure I follow how to access such specific properties.

Categories