我晕了。。搞不懂list, array, tensor, numpy这些的区别和特点。。所以来总结一下

一、概念

list(列表)可以存储不同类型的data,但是整体不够高效。值得一提的是,python中还有一个类似的结构是tuple(元组),两者的区别在于list可以改变内容,而tuple不行。e.g., list = [1,2,3], tuple = (1,2,3)

array(数组)比较高效。python本身没有数组的概念(有list和tuple),但是可以通过numpy.array来实现。 

tensor 张量

list, array, tensor, numpy格式辨别

PyTorch中的Tensor可以和numpy的ndarray相互转换,唯一不同的是PyTorch可以在GPU上运行,而numpy的ndarray只能在cpu上运行。

numpy (Numerical Python) 是 Python 语言的一个扩展程序库,支持大量的维度数组与矩阵运算,此外也针对数组运算提供大量的数学函数库。

二、重点谈一下numpy.array

例如:

a1 = np.array([[1, 2], [3, 4]])

[[1 2]
 [3 4]]
shape:  (2, 2)
dim:  2

a2 = np.array([[[1,2]]])

[[[1 2]]]
shape:  (1, 1, 2)
dim:  3

a3 = np.array([[[1,2], [3,4]]])

[[[1 2]
  [3 4]]]
shape:  (1, 2, 2)
dim:  3

左右两边连续几个方括号,即为几维。

三、数据type之间的转换

https://www.cnblogs.com/siyuan1998/p/10792481.html

 

参考链接:

https://www.cnblogs.com/sunlong88/articles/9384920.html

https://blog.csdn.net/fu6543210/article/details/83240024

https://blog.csdn.net/qq_41992047/article/details/94015668

 

 

相关文章:

  • 2021-08-22
  • 2022-01-20
  • 2021-08-19
  • 2021-10-12
  • 2021-10-06
  • 2021-10-15
  • 2021-08-31
  • 2022-12-23
猜你喜欢
  • 2022-01-10
  • 2022-12-23
  • 2022-12-23
  • 2021-11-03
  • 2022-12-23
  • 2021-05-15
  • 2021-10-13
相关资源
相似解决方案