2. 定义一个数组(二维),按列计算数组的最大值 max,最小值 min,均值 mean,要求每种特征值均为一种函
时间: 2024-05-10 21:18:55 浏览: 44
数的实现方式。
假设二维数组为arr,有n行m列,其中每个元素为arr[i][j]。
1. 计算最大值max
```python
def get_max(arr):
n = len(arr) # 行数
m = len(arr[0]) # 列数
max_list = []
for j in range(m):
max_val = arr[0][j]
for i in range(1, n):
if arr[i][j] > max_val:
max_val = arr[i][j]
max_list.append(max_val)
return max_list
```
2. 计算最小值min
```python
def get_min(arr):
n = len(arr) # 行数
m = len(arr[0]) # 列数
min_list = []
for j in range(m):
min_val = arr[0][j]
for i in range(1, n):
if arr[i][j] < min_val:
min_val = arr[i][j]
min_list.append(min_val)
return min_list
```
3. 计算均值mean
```python
def get_mean(arr):
n = len(arr) # 行数
m = len(arr[0]) # 列数
mean_list = []
for j in range(m):
sum_val = 0
for i in range(n):
sum_val += arr[i][j]
mean_val = sum_val / n
mean_list.append(mean_val)
return mean_list
```
阅读全文