python 中List 与array互换

来源:互联网 发布:电路接线仿真软件 编辑:程序博客网 时间:2024/05/16 08:20

输入list:

>>> import numpy as np>>> a = [[1,2],[3,4]]>>> type(a)<class 'list'>

将list转换为数组:

>>> b = np.array(a)>>> barray([[1, 2],       [3, 4]])>>> type(b)<class 'numpy.ndarray'>

将数组转换为list:

>>> c = b.tolist()>>> c[[1, 2], [3, 4]]>>> type(c)<class 'list'>
阅读全文
0 0