Lassen Sie zweifarbige Fische im Aquarium leben.
Beginnen wir mit der Visualisierung. Stellen wir die Anzahl der Fische n = 100 ein und stimmen zu, dass jeder von ihnen eine zufällige Farbe # 0 oder # 1 hat und sich auch an einem zufälligen Punkt (x, y) befindet. Jene. x, y und Farbe sind drei Vektoren der Länge n, und die dritte (z-) Koordinate wird nicht berücksichtigt.
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
n = 100
x, y = np.random.rand(n), np.random.rand(n)
color = np.random.randint(0, 2, n)
plt.scatter(x, y, c=color)
Die gleichen drei Vektoren in Mathcad Express können wie folgt generiert werden:
x,y (0, 1), color — , , , . Mathcad 47 №1 100-47=53 .
: 0 1?
, , . , . , , (0 1) (" "). ( ) , , , (, -) .
, .. :
00
( , ) 01
11
, i- , — , , . , 00, 10, 01 11. , — .
n = 3
Aa = np.zeros((n,2))
color = np.zeros(n)
for i in range(n):
Aa[i,0] = np.random.randint(0, 2, 1)
Aa[i,1] = np.random.randint(0, 2, 1)
color[i] = Aa[i,0] * Aa[i,1]
print (Aa)
print (color)
:
, , , 25%. Mathcad n=1000 .
YouTube , .. , — . , , , Python, Mathcad , . .