Even if you can draw a heart with Python, you're still a single dog.

Source: Internet
Author: User



:) The title is a joke, please don't be serious.

With the rapid development of AI, is interested in this line of the code of the farmers is also a sharp increase, bringing the algorithm, the interest of mathematics is also exceptionally high.
The origin of this article is this, today an old colleague in the circle of friends sent a screen shot, to find formulas.

It is still difficult to see, the upper half is basically two semicircular, the lower half is two rotated inverse cosine function.
But my math is also relatively slag, see this step behind also daoteng unclear, but to this extent on the Internet search search Find the answer or not difficult, quickly found the right formula (with y=0 as the boundary, it is definitely need two sets of solutions):


$$ y = \sqrt{1-(\left| x \right|-1) ^2}, Arccos (1-\left| x \right|) -\pi $$


Otherwise just search the heart-shaped function, will certainly get a large variety of, but do not match test instructions pictures, such as:

To verify this formula with Mathmatics most convenient, but just changed the computer, just not installed.

Recently in the area of doing python3, 5 minutes with Python3 wrote a verification program, the source attached:

#!/usr/bin/env Python3ImportMatplotlib.pyplot asPlt fromMatplotlib.font_managerImportFontpropertiesImportNumPy asmp[=Np.linspace (-2,2, $) y1=NP.SQRT (1-Np.square (Np.fabs (x)-1)) Y2=Np.arccos (1-Np.fabs (x))-Np.piplt.plot (x, y1,' R ', X,y2,' R ') Plt.axis ([-2.5,2.5,-3.5,1.5]) Plt.title (' Heart of Numbers, by @andrew ', FontSize= -) Plt.show ()

The result of the drawing is the head graph.
The program used to Matplotlib and numpy two libraries, before running the need to first install with PIP3.

Resources

Https://www.quora.com/What-is-the-equation-that-gives-you-a-heart-on-the-graph

Even if you can draw a heart with Python, you're still a single dog.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.