For this tutorial, you may need to read the Wikipedia page about Pythagorean triple (http://en.wikipedia.org/wiki/Pythagorean_triple). A Pythagorean triple is a set of three natural numbers, a < b < c, for which .
Here is an example of Pythagorean triples: .
Pythagorean triples are closely related to the Pythagorean Theorem, which you have probably learned in high-school geometry.
Pythagorean triples represent the three sides of a right triangle and therefore obey the Pythagorean Theorem. Let's find the Pythagorean triple that has a components sum of 1,000. We will do this using Euclid's formula:
In this example, we will see universal functions in action.
Euclid's formula defines the m
and n
indices.
Create arrays to hold these indices:
m = np.arange(33) n = np.arange(33)
The second step is to calculate the numbers
a
,b
, andc
of the Pythagorean triples using Euclid's formula. Use theouter()
function to get the Cartesian products, difference, and...