简述
- 先安装个pycharm(或者其他类似的)。
- 点击文件—》设置—》项目—》python解释器
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/56b89cf7545359e443c4e3d197e8ef35.png)
- 点击pip,搜索“numpy”,选中搜索结果,点击左下的“安装内容”
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/cf8a517cf387f32048c53077860cb70a.png)
- 复制粘贴之后把所有的打印语句打开即可
代码
import numpy as np
a = np.array([[1, 3, 9, 6, 8], [4, 1, 2, 7, 4], [3, 6, 0, 6, 4], [6, 6, 3, 1, 5]])
def count(array):
count_num = []
for k in range(10):
num = 0
for i in range(array.shape[0]):
for j in range(array.shape[1]):
if a[i, j] == k:
num = num + 1
if i == 3 and j == 4:
count_num.append(num)
return count_num
def distribution_probability(array):
count_rate = []
count_num = count(array)
for num in count_num:
count_rate.append(format(float(num / array.size), '.2f'))
return count_rate
def cumulative_probability(array):
cumulative_rate = []
count_rate = distribution_probability(array)
s = 0
for rate in count_rate:
s = s + float(rate)
cumulative_rate.append(format(float(s), '.2f'))
return cumulative_rate
def insinuation(array, limit):
insinuation_list = list(range(limit[0], limit[1]))
cumulative_rate = cumulative_probability(array)
for i in range(len(cumulative_rate)):
z = round(float(insinuation_list[i]) * float(cumulative_rate[i]))
if z < limit[0]:
z = limit[0]
insinuation_list[i] = z
return insinuation_list
b = np.array([[1, 0, 9, 16, 18], [4, 5, 8, 17, 14], [3, 6, 10, 11, 16], [2, 7, 13, 12, 15]])
def new_image_size(array, k1, k2):
m = array.shape[0]
n = array.shape[1]
m1 = round(m * k1)
n1 = round(n * k2)
size = [m1, n1]
return size
def image_corresponding_position(array, k1, k2):
size = new_image_size(array, k1, k2)
row = []
for i in range(1, size[0] + 1):
r = round(i / k1)
row.append(r)
col = []
for j in range(1, size[1] + 1):
c = round(j / k2)
col.append(c)
return row, col
C = np.array([[3, 2, 5], [6, 6, 4], [4, 7, 8]])