我需要使用 numpy 将数组写入文件,并且我正在尝试将数组作为原始输入读取并将其转换为数组。我的问题似乎来自 line
inarray = np.array(inlist)
,因为代码没有返回数组。这是我的整个代码:
import numpy as np
def write():
inlist = raw_input('Please enter a square array of booleans.')
print inlist
inarray = np.array(inlist)
print inarray
dims = inarray.shape
print dims
dim = dims[0]
name = open(name,'w')
name.write(dims)
dimint = int(dim)
i = 0
while i < dimint:
name.write(inarray[i])
i = i+1
return name
write()