在矩阵列中对所选字符串排序

2024-09-30 22:14:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我们要对“名字”进行分类,同时确保给正确的学生适当的分数。你知道吗

print("List of grades are:")
grraids=computeFinalGrade(pure_data)
kn=np.column_stack((names,grraids))
for names in sorted(kn):
    print(kn)

enter image description here

我们得到了,但非常希望这些名字是在alphebetic顺序,但保持功能一般。你知道吗


Tags: ofdatanamespure分类名字学生分数
1条回答
网友
1楼 · 发布于 2024-09-30 22:14:21

编辑:抱歉,没有意识到这是一个numy数组,代码已经相应地更改。然而,它仍然假设学生的名字总是在同一个地方。(第一个点)

import numpy as np
grades = np.array([["B",10],["C",8],["A",3]])
print grades
grades.sort(axis=0)
print grades

输出:

[['B' '10']
 ['C' '8']
 ['A' '3']]
[['A' '10']
 ['B' '3']
 ['C' '8']]

相关问题 更多 >