numpy 初识(一)

文件操作:

  • 读取文件(与pandas读取csv相似):
import numpy
numpy.genfromtxt("word.txt", delimiter=',', dtype=str)
# => <class 'numpy.ndarray'>
  • numpy.array(序列)
# 一维向量
vector = numpy.array([1, 2, 3, 4])
print(vector.shape)

# 二维矩阵
matrix = numpy.array([[5, 10, 15], [20, 25, 30]])
print(matrix.shape)
(4,)
(2, 3)

猜你喜欢

转载自www.cnblogs.com/spaceapp/p/10646164.html