如何从保存为文本文件的数组列表中导入和提取元素 python

How to Import and extract elements from a list of arrays saved as a text file in python

我有一个 .txt 文件,它是一个数组列表。我想导入该文件并提取该数组列表的元素并使用它们。 当我使用

with open('filename.txt') as f:
        list1 = eval(f.read())

当我想导入数字列表时效果很好,当元素是数组时不起作用。它给出

NameError: name 'array' is not defined

问题可能出在 eval() 函数不能很好地处理数组?你能帮我导入这个数组列表吗?

如果文件内容是,例如:

array([1,2,3])

...然后...

from numpy import array

with open('filename.txt') as f:
    a = eval(f.read())
    print(a)
    print(type(a))

...将产生...

[1 2 3]
<class 'numpy.ndarray'>