我有一个矩阵,其中第一列和第一行由字符串组成,其余部分是浮点数:
[["City","Score1","Score2","Score3"],
["Berkley",23,432,321],
["Ohio",3,432,54],
["Columbia",123,432,53]]
我只需要制作另一个矩阵来存储花车。 它看起来像这样:
[[23,432,321],
[3,432,54],
[123,432,53]]
答案 0 :(得分:4)
使用numpy:
import numpy as np
arr = np.array([["City","Score1","Score2","Score3"],
["Berkley",23,432,321],
["Ohio",3,432,54],
["Columbia",123,432,53]])
new_arr = arr[1:, 1:].astype(float)
注意:在您的示例中,这些内容不是浮点数,但我仍然在这里使用浮点数