我想将一个大文本文件(大约 1 GB,3*10^6 行和 10 - 100 列)加载为包含字符串的 2D np 数组。但是,似乎 numpy.loadtxt() 仅将浮点数作为默认值。是否可以为整个数组指定另一种数据类型?我试过以下没有运气:
loadedData = np.loadtxt(address, dtype=np.str)
我收到以下错误消息:
/Library/Python/2.7/site-packages/numpy-1.8.0.dev_20224ea_20121123-py2.7-macosx-10.8-x86_64.egg/numpy/lib/npyio.pyc in loadtxt(fname, dtype, comments, delimiter, converters, skiprows, usecols, unpack, ndmin)
833 fh.close()
834
--> 835 X = np.array(X, dtype)
836 # Multicolumn data are returned with shape (1, N, M), i.e.
837 # (1, 1, M) for a single row - remove the singleton dimension there
ValueError: cannot set an array element with a sequence
有任何想法吗?(我事先不知道我的文件中的确切列数。)