• 技术文章 >常见问题 >Python常见问题

    python怎么把list变成array

    yangyang2020-04-08 11:16:58原创5972

    将list转换成数组:

    由于list中可以存放不同类型的元素,因此在转换成数组时,为了保证转换不出错,要检查类型是否一致,有数字且有字符的list转成array时会变成字符数组。

    import numpy as np
    # define list
    array = np.asarray(list)
    #the second method
    array = np.array(list, dtype = int)

    更多Python知识请关注Python视频教程栏目。

    专题推荐:python
    品易云
    上一篇:python(x,y)是什么 下一篇:python中怎么交换列的顺序

    相关文章推荐

    • python编程如何删除字符• 为什么python下载好慢

    全部评论我要评论

    © 2021 Python学习网 苏ICP备2021003149号-1

  • 取消发布评论
  • 

    Python学习网