You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Python中如何将数组组成的列表转换为7×3矩阵?

嵌套数组转标准矩阵的实现方法

直接用NumPy就能快速完成转换,因为它原生支持将数组列表转换为二维矩阵:

import numpy as np

# 你的原始嵌套数组列表
nested_arrays = [
    np.array([ -99.21898 , -200.566483,    0.58519 ]),
    np.array([-1.00395332e+02, -2.05700867e+02,  6.47600000e-02]),
    np.array([-9.99833530e+01, -200.824783e+02,  6.77800000e-02]),
    np.array([ -99.951599, -200.833435,    0.52976 ]),
    np.array([-100.375549, -205.394653,    0.58454 ]),
    np.array([-100.453751, -205.939728,    0.58379 ]),
    np.array([ -99.921898, -200.566483,    0.58519 ])
]

# 转换为7×3矩阵
matrix = np.array(nested_arrays)

# 验证矩阵形状
print(matrix.shape)  # 输出 (7, 3)

如果不需要NumPy对象,只想得到普通的二维列表矩阵,用列表推导式结合数组的tolist()方法即可:

# 转换为普通二维列表
matrix_list = [arr.tolist() for arr in nested_arrays]

# 检查维度
print(f"矩阵维度:{len(matrix_list)}×{len(matrix_list[0])}")  # 输出 矩阵维度:7×3

内容的提问来源于stack exchange,提问作者ABh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.11 04:15:17