Let fish of two colors live in the aquarium.
Let's start with visualization. Let's set the number of fish n = 100 and agree that each of them has a random color # 0 or # 1, and is also located at a random point (x, y). Those. x, y, and color are three vectors of length n, and the third (z-) coordinate is not considered.
%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)
The same three vectors in Mathcad Express can be generated as follows:
x,y (0, 1), color β , , , . Mathcad 47 β1 100-47=53 .
: 0 1?
, , . , . , , (0 1) (" "). ( ) , , , (, -) .
, .. :
00
( , ) 01
11
, , β . .. , (0) , (1) β .
, 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 , . .