import numpy as np
# read file and split over whitespace
with open('dat.xyz', 'r') as f:
rows = f.read()
rows = rows.split(' ')
arr = []
# split each value in row over comma, then convert each element to integer
for row in rows:
row = row.split(',')
for i in range(len(row)):
row[i] = int(row[i])
arr.append(row)
# convert to array
arr = np.array(arr)
arr
输出:
array([[2, 3, 4, 5, 6, 7, 8, 9],
[2, 3, 4, 5, 6, 7, 8, 9],
[2, 3, 4, 5, 6, 7, 8, 9],
[2, 3, 4, 5, 6, 7, 8, 9]])