将空格分隔的txt数组读入numpy

发布于 2025-01-18 02:23:34 字数 3671 浏览 0 评论 0原文

我有一个充满 .txt 文件的文件夹,其格式如下(一个示例,下面是 0.txt):

[[[ 2.1032608e+01  3.2608695e+00  1.4498953e-02]
  [ 2.1032608e+01  3.0978260e+00  6.5927312e-04]
  [ 3.0652174e+01  5.6739132e+01  1.1040760e-04]
  [ 3.0489130e+01  5.6576088e+01  6.9526240e-04]
  [ 1.6141304e+01  2.1684782e+01  1.5140385e-03]
  [ 1.6141304e+01  2.1684782e+01  2.4998910e-03]
  [ 3.5706520e+01  1.5163043e+01  1.5667630e-02]
  [ 3.5706520e+01  1.5163043e+01  5.1132514e-04]
  [ 1.6141304e+01  2.1521740e+01  9.0042617e-05]
  [ 1.5652174e+01  2.0217392e+01  4.7678968e-05]
  [ 3.3097828e+01  5.8043480e+01  2.3867608e-04]
  [ 1.5652174e+01  2.0217392e+01  1.3099676e-04]
  [ 1.7445652e+01  3.3097828e+01  8.3532266e-04]
  [ 1.8423914e+01  2.5597826e+01  1.5159410e-02]
  [ 3.8967392e+01  5.9673912e+01  6.5958439e-03]
  [ 3.8967392e+01  5.9673912e+01  9.2201140e-03]
  [ 1.5652174e+01  2.0054348e+01  9.5022479e-03]
  [ 3.3097828e+01  3.9782608e+01  1.6697637e-04]
  [ 3.3260868e+01  3.9619564e+01  2.7213297e-03]
  [ 3.3260868e+01  3.9619564e+01  2.1958089e-04]
  [ 1.6141304e+01  2.1684782e+01  5.6157220e-05]
  [ 2.1032608e+01  3.0978260e+00 -1.0377635e-05]
  [ 2.1032608e+01  3.0978260e+00 -8.7080858e-05]
  [ 1.5652174e+01  2.0217392e+01 -1.1274265e-04]
  [ 1.5652174e+01  2.0054348e+01 -5.1815634e-05]
  [ 3.2119564e+01  5.9673912e+01 -1.6645924e-04]
  [ 1.5652174e+01  2.0217392e+01  7.7641735e-06]
  [ 3.2608697e-01  1.7934783e+00  3.5882247e-05]
  [ 2.1032608e+01  3.0978260e+00  7.8685611e-05]
  [ 1.5652174e+01  2.0054348e+01  3.1178934e-05]
  [ 3.8967392e+01  5.9673912e+01  1.0482615e-04]
  [ 3.1956522e+01  5.6739132e+01  1.0767143e-03]
  [ 3.1793478e+01  5.6739132e+01  6.9617934e-04]
  [ 3.1956522e+01  5.6739132e+01  1.2175621e-04]
  [ 3.2119564e+01  5.9673912e+01  8.6526132e-05]
  [ 3.8967392e+01  5.9673912e+01  7.2365336e-05]
  [ 3.5706520e+01  1.5163043e+01  1.3151739e-04]
  [ 2.1032608e+01  3.0978260e+00  4.4964137e-05]
  [ 2.1032608e+01  3.0978260e+00 -1.4677797e-05]
  [ 3.5706520e+01  1.5163043e+01 -1.1417971e-05]
  [ 2.1032608e+01  3.0978260e+00  1.2694198e-05]
  [ 2.1032608e+01  3.0978260e+00  8.1792423e-05]
  [ 3.2119564e+01  5.9673912e+01 -4.8189460e-05]
  [ 1.5652174e+01  2.0217392e+01 -1.2792133e-04]
  [ 3.2445652e+01  5.9673912e+01 -1.1050291e-04]
  [ 1.5652174e+01  2.0217392e+01 -4.2534582e-05]
  [ 3.2282608e+01  5.9673912e+01 -3.9592214e-05]
  [ 3.2445652e+01  5.9673912e+01 -1.2300081e-04]
  [ 3.2119564e+01  5.9673912e+01  1.3895029e-04]
  [ 3.2119564e+01  5.9673912e+01  4.5048160e-04]
  [ 3.2119564e+01  5.9673912e+01  2.8149947e-03]
  [ 3.2119564e+01  5.9673912e+01  2.4660570e-03]
  [ 3.2119564e+01  5.9673912e+01  1.1084687e-05]
  [ 1.8423914e+01  2.5597826e+01  2.7254851e-05]
  [ 1.8423914e+01  2.5597826e+01  4.5520133e-06]
  [ 3.5706520e+01  1.5163043e+01  1.3295857e-05]
  [ 3.2282608e+01  5.9673912e+01  4.1052594e-06]
  [ 3.2119564e+01  5.9673912e+01  5.6243367e-05]
  [ 3.3097828e+01  5.8206520e+01  2.3062130e-05]
  [ 3.2119564e+01  5.9673912e+01  6.7559289e-05]
  [ 3.2119564e+01  5.9673912e+01  6.5806766e-05]
  [ 3.2119564e+01  5.9673912e+01  9.2756242e-04]
  [ 3.2119564e+01  5.9673912e+01  5.2335125e-04]
  [ 3.2282608e+01  5.9673912e+01  3.2513806e-05]
  [ 1.8423914e+01  2.5597826e+01  1.3968185e-05]
  [ 3.2119564e+01  5.9673912e+01  1.5303758e-05]
  [ 1.6141304e+01  2.1684782e+01  1.7933089e-05]
  [ 3.2119564e+01  5.9673912e+01  6.1444991e-04]
  [ 2.1032608e+01  3.0978260e+00  2.0746856e-04]
  [ 1.5652174e+01  2.0054348e+01 -9.7850330e-05]]]

有没有办法将其读入 2d numpy 数组?请注意,它是由两个空格分隔的空格,但当有负数时, - 符号代替其中一个空格。任何帮助将不胜感激!

我尝试将其读入 pandas 并以各种方式进行解析(使用 df.str 去掉括号等),但我似乎无法让它以科学记数法读取的方式工作。我在这里尝试了正则表达式方法。

I have a folder full of .txt files with the following format (one example, 0.txt below):

[[[ 2.1032608e+01  3.2608695e+00  1.4498953e-02]
  [ 2.1032608e+01  3.0978260e+00  6.5927312e-04]
  [ 3.0652174e+01  5.6739132e+01  1.1040760e-04]
  [ 3.0489130e+01  5.6576088e+01  6.9526240e-04]
  [ 1.6141304e+01  2.1684782e+01  1.5140385e-03]
  [ 1.6141304e+01  2.1684782e+01  2.4998910e-03]
  [ 3.5706520e+01  1.5163043e+01  1.5667630e-02]
  [ 3.5706520e+01  1.5163043e+01  5.1132514e-04]
  [ 1.6141304e+01  2.1521740e+01  9.0042617e-05]
  [ 1.5652174e+01  2.0217392e+01  4.7678968e-05]
  [ 3.3097828e+01  5.8043480e+01  2.3867608e-04]
  [ 1.5652174e+01  2.0217392e+01  1.3099676e-04]
  [ 1.7445652e+01  3.3097828e+01  8.3532266e-04]
  [ 1.8423914e+01  2.5597826e+01  1.5159410e-02]
  [ 3.8967392e+01  5.9673912e+01  6.5958439e-03]
  [ 3.8967392e+01  5.9673912e+01  9.2201140e-03]
  [ 1.5652174e+01  2.0054348e+01  9.5022479e-03]
  [ 3.3097828e+01  3.9782608e+01  1.6697637e-04]
  [ 3.3260868e+01  3.9619564e+01  2.7213297e-03]
  [ 3.3260868e+01  3.9619564e+01  2.1958089e-04]
  [ 1.6141304e+01  2.1684782e+01  5.6157220e-05]
  [ 2.1032608e+01  3.0978260e+00 -1.0377635e-05]
  [ 2.1032608e+01  3.0978260e+00 -8.7080858e-05]
  [ 1.5652174e+01  2.0217392e+01 -1.1274265e-04]
  [ 1.5652174e+01  2.0054348e+01 -5.1815634e-05]
  [ 3.2119564e+01  5.9673912e+01 -1.6645924e-04]
  [ 1.5652174e+01  2.0217392e+01  7.7641735e-06]
  [ 3.2608697e-01  1.7934783e+00  3.5882247e-05]
  [ 2.1032608e+01  3.0978260e+00  7.8685611e-05]
  [ 1.5652174e+01  2.0054348e+01  3.1178934e-05]
  [ 3.8967392e+01  5.9673912e+01  1.0482615e-04]
  [ 3.1956522e+01  5.6739132e+01  1.0767143e-03]
  [ 3.1793478e+01  5.6739132e+01  6.9617934e-04]
  [ 3.1956522e+01  5.6739132e+01  1.2175621e-04]
  [ 3.2119564e+01  5.9673912e+01  8.6526132e-05]
  [ 3.8967392e+01  5.9673912e+01  7.2365336e-05]
  [ 3.5706520e+01  1.5163043e+01  1.3151739e-04]
  [ 2.1032608e+01  3.0978260e+00  4.4964137e-05]
  [ 2.1032608e+01  3.0978260e+00 -1.4677797e-05]
  [ 3.5706520e+01  1.5163043e+01 -1.1417971e-05]
  [ 2.1032608e+01  3.0978260e+00  1.2694198e-05]
  [ 2.1032608e+01  3.0978260e+00  8.1792423e-05]
  [ 3.2119564e+01  5.9673912e+01 -4.8189460e-05]
  [ 1.5652174e+01  2.0217392e+01 -1.2792133e-04]
  [ 3.2445652e+01  5.9673912e+01 -1.1050291e-04]
  [ 1.5652174e+01  2.0217392e+01 -4.2534582e-05]
  [ 3.2282608e+01  5.9673912e+01 -3.9592214e-05]
  [ 3.2445652e+01  5.9673912e+01 -1.2300081e-04]
  [ 3.2119564e+01  5.9673912e+01  1.3895029e-04]
  [ 3.2119564e+01  5.9673912e+01  4.5048160e-04]
  [ 3.2119564e+01  5.9673912e+01  2.8149947e-03]
  [ 3.2119564e+01  5.9673912e+01  2.4660570e-03]
  [ 3.2119564e+01  5.9673912e+01  1.1084687e-05]
  [ 1.8423914e+01  2.5597826e+01  2.7254851e-05]
  [ 1.8423914e+01  2.5597826e+01  4.5520133e-06]
  [ 3.5706520e+01  1.5163043e+01  1.3295857e-05]
  [ 3.2282608e+01  5.9673912e+01  4.1052594e-06]
  [ 3.2119564e+01  5.9673912e+01  5.6243367e-05]
  [ 3.3097828e+01  5.8206520e+01  2.3062130e-05]
  [ 3.2119564e+01  5.9673912e+01  6.7559289e-05]
  [ 3.2119564e+01  5.9673912e+01  6.5806766e-05]
  [ 3.2119564e+01  5.9673912e+01  9.2756242e-04]
  [ 3.2119564e+01  5.9673912e+01  5.2335125e-04]
  [ 3.2282608e+01  5.9673912e+01  3.2513806e-05]
  [ 1.8423914e+01  2.5597826e+01  1.3968185e-05]
  [ 3.2119564e+01  5.9673912e+01  1.5303758e-05]
  [ 1.6141304e+01  2.1684782e+01  1.7933089e-05]
  [ 3.2119564e+01  5.9673912e+01  6.1444991e-04]
  [ 2.1032608e+01  3.0978260e+00  2.0746856e-04]
  [ 1.5652174e+01  2.0054348e+01 -9.7850330e-05]]]

Is there any way to read this into a 2d numpy array? Notice that it is space delimited by two spaces, but when there is a negative number, the - sign is in place of one of the spaces. Any help would be greatly appreciated!

I tried reading it into pandas and parsing in various ways (using df.str to strip out brackets etc), but I couldn't seem to get it working in a way which reads in the scientific notation. I tried a regex approach here.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

木格 2025-01-25 02:23:34

用途:

import re
with open('01.txt') as file:
    p = file.read()

rows = p.split('\n')
ll = []
for row in rows:
    ll.append(re.findall('[\d+-\.e]+', row))
np.array(ll, dtype=float)

输出:

array([[ 2.1032608e+01,  3.2608695e+00,  1.4498953e-02],
   [ 2.1032608e+01,  3.0978260e+00,  6.5927312e-04],
   [ 3.0652174e+01,  5.6739132e+01,  1.1040760e-04],
   [ 3.0489130e+01,  5.6576088e+01,  6.9526240e-04],
   [ 1.6141304e+01,  2.1684782e+01,  1.5140385e-03],
   [ 1.6141304e+01,  2.1684782e+01,  2.4998910e-03],
   [ 3.5706520e+01,  1.5163043e+01,  1.5667630e-02],
   [ 3.5706520e+01,  1.5163043e+01,  5.1132514e-04],
   [ 1.6141304e+01,  2.1521740e+01,  9.0042617e-05],
   [ 1.5652174e+01,  2.0217392e+01,  4.7678968e-05],
   [ 3.3097828e+01,  5.8043480e+01,  2.3867608e-04],
   [ 1.5652174e+01,  2.0217392e+01,  1.3099676e-04],
   [ 1.7445652e+01,  3.3097828e+01,  8.3532266e-04],
   [ 1.8423914e+01,  2.5597826e+01,  1.5159410e-02],
   [ 3.8967392e+01,  5.9673912e+01,  6.5958439e-03],
   [ 3.8967392e+01,  5.9673912e+01,  9.2201140e-03],
   [ 1.5652174e+01,  2.0054348e+01,  9.5022479e-03],
   [ 3.3097828e+01,  3.9782608e+01,  1.6697637e-04],
   [ 3.3260868e+01,  3.9619564e+01,  2.7213297e-03],
   [ 3.3260868e+01,  3.9619564e+01,  2.1958089e-04],
   [ 1.6141304e+01,  2.1684782e+01,  5.6157220e-05],
   [ 2.1032608e+01,  3.0978260e+00, -1.0377635e-05],
   [ 2.1032608e+01,  3.0978260e+00, -8.7080858e-05],
   [ 1.5652174e+01,  2.0217392e+01, -1.1274265e-04],
   [ 1.5652174e+01,  2.0054348e+01, -5.1815634e-05],
   [ 3.2119564e+01,  5.9673912e+01, -1.6645924e-04],
   [ 1.5652174e+01,  2.0217392e+01,  7.7641735e-06],
   [ 3.2608697e-01,  1.7934783e+00,  3.5882247e-05],
   [ 2.1032608e+01,  3.0978260e+00,  7.8685611e-05],
   [ 1.5652174e+01,  2.0054348e+01,  3.1178934e-05],
   [ 3.8967392e+01,  5.9673912e+01,  1.0482615e-04],
   [ 3.1956522e+01,  5.6739132e+01,  1.0767143e-03],
   [ 3.1793478e+01,  5.6739132e+01,  6.9617934e-04],
   [ 3.1956522e+01,  5.6739132e+01,  1.2175621e-04],
   [ 3.2119564e+01,  5.9673912e+01,  8.6526132e-05],
   [ 3.8967392e+01,  5.9673912e+01,  7.2365336e-05],
   [ 3.5706520e+01,  1.5163043e+01,  1.3151739e-04],
   [ 2.1032608e+01,  3.0978260e+00,  4.4964137e-05],
   [ 2.1032608e+01,  3.0978260e+00, -1.4677797e-05],
   [ 3.5706520e+01,  1.5163043e+01, -1.1417971e-05],
   [ 2.1032608e+01,  3.0978260e+00,  1.2694198e-05],
   [ 2.1032608e+01,  3.0978260e+00,  8.1792423e-05],
   [ 3.2119564e+01,  5.9673912e+01, -4.8189460e-05],
   [ 1.5652174e+01,  2.0217392e+01, -1.2792133e-04],
   [ 3.2445652e+01,  5.9673912e+01, -1.1050291e-04],
   [ 1.5652174e+01,  2.0217392e+01, -4.2534582e-05],
   [ 3.2282608e+01,  5.9673912e+01, -3.9592214e-05],
   [ 3.2445652e+01,  5.9673912e+01, -1.2300081e-04],
   [ 3.2119564e+01,  5.9673912e+01,  1.3895029e-04],
   [ 3.2119564e+01,  5.9673912e+01,  4.5048160e-04],
   [ 3.2119564e+01,  5.9673912e+01,  2.8149947e-03],
   [ 3.2119564e+01,  5.9673912e+01,  2.4660570e-03],
   [ 3.2119564e+01,  5.9673912e+01,  1.1084687e-05],
   [ 1.8423914e+01,  2.5597826e+01,  2.7254851e-05],
   [ 1.8423914e+01,  2.5597826e+01,  4.5520133e-06],
   [ 3.5706520e+01,  1.5163043e+01,  1.3295857e-05],
   [ 3.2282608e+01,  5.9673912e+01,  4.1052594e-06],
   [ 3.2119564e+01,  5.9673912e+01,  5.6243367e-05],
   [ 3.3097828e+01,  5.8206520e+01,  2.3062130e-05],
   [ 3.2119564e+01,  5.9673912e+01,  6.7559289e-05],
   [ 3.2119564e+01,  5.9673912e+01,  6.5806766e-05],
   [ 3.2119564e+01,  5.9673912e+01,  9.2756242e-04],
   [ 3.2119564e+01,  5.9673912e+01,  5.2335125e-04],
   [ 3.2282608e+01,  5.9673912e+01,  3.2513806e-05],
   [ 1.8423914e+01,  2.5597826e+01,  1.3968185e-05],
   [ 3.2119564e+01,  5.9673912e+01,  1.5303758e-05],
   [ 1.6141304e+01,  2.1684782e+01,  1.7933089e-05],
   [ 3.2119564e+01,  5.9673912e+01,  6.1444991e-04],
   [ 2.1032608e+01,  3.0978260e+00,  2.0746856e-04],
   [ 1.5652174e+01,  2.0054348e+01, -9.7850330e-05]])

Use:

import re
with open('01.txt') as file:
    p = file.read()

rows = p.split('\n')
ll = []
for row in rows:
    ll.append(re.findall('[\d+-\.e]+', row))
np.array(ll, dtype=float)

Output:

array([[ 2.1032608e+01,  3.2608695e+00,  1.4498953e-02],
   [ 2.1032608e+01,  3.0978260e+00,  6.5927312e-04],
   [ 3.0652174e+01,  5.6739132e+01,  1.1040760e-04],
   [ 3.0489130e+01,  5.6576088e+01,  6.9526240e-04],
   [ 1.6141304e+01,  2.1684782e+01,  1.5140385e-03],
   [ 1.6141304e+01,  2.1684782e+01,  2.4998910e-03],
   [ 3.5706520e+01,  1.5163043e+01,  1.5667630e-02],
   [ 3.5706520e+01,  1.5163043e+01,  5.1132514e-04],
   [ 1.6141304e+01,  2.1521740e+01,  9.0042617e-05],
   [ 1.5652174e+01,  2.0217392e+01,  4.7678968e-05],
   [ 3.3097828e+01,  5.8043480e+01,  2.3867608e-04],
   [ 1.5652174e+01,  2.0217392e+01,  1.3099676e-04],
   [ 1.7445652e+01,  3.3097828e+01,  8.3532266e-04],
   [ 1.8423914e+01,  2.5597826e+01,  1.5159410e-02],
   [ 3.8967392e+01,  5.9673912e+01,  6.5958439e-03],
   [ 3.8967392e+01,  5.9673912e+01,  9.2201140e-03],
   [ 1.5652174e+01,  2.0054348e+01,  9.5022479e-03],
   [ 3.3097828e+01,  3.9782608e+01,  1.6697637e-04],
   [ 3.3260868e+01,  3.9619564e+01,  2.7213297e-03],
   [ 3.3260868e+01,  3.9619564e+01,  2.1958089e-04],
   [ 1.6141304e+01,  2.1684782e+01,  5.6157220e-05],
   [ 2.1032608e+01,  3.0978260e+00, -1.0377635e-05],
   [ 2.1032608e+01,  3.0978260e+00, -8.7080858e-05],
   [ 1.5652174e+01,  2.0217392e+01, -1.1274265e-04],
   [ 1.5652174e+01,  2.0054348e+01, -5.1815634e-05],
   [ 3.2119564e+01,  5.9673912e+01, -1.6645924e-04],
   [ 1.5652174e+01,  2.0217392e+01,  7.7641735e-06],
   [ 3.2608697e-01,  1.7934783e+00,  3.5882247e-05],
   [ 2.1032608e+01,  3.0978260e+00,  7.8685611e-05],
   [ 1.5652174e+01,  2.0054348e+01,  3.1178934e-05],
   [ 3.8967392e+01,  5.9673912e+01,  1.0482615e-04],
   [ 3.1956522e+01,  5.6739132e+01,  1.0767143e-03],
   [ 3.1793478e+01,  5.6739132e+01,  6.9617934e-04],
   [ 3.1956522e+01,  5.6739132e+01,  1.2175621e-04],
   [ 3.2119564e+01,  5.9673912e+01,  8.6526132e-05],
   [ 3.8967392e+01,  5.9673912e+01,  7.2365336e-05],
   [ 3.5706520e+01,  1.5163043e+01,  1.3151739e-04],
   [ 2.1032608e+01,  3.0978260e+00,  4.4964137e-05],
   [ 2.1032608e+01,  3.0978260e+00, -1.4677797e-05],
   [ 3.5706520e+01,  1.5163043e+01, -1.1417971e-05],
   [ 2.1032608e+01,  3.0978260e+00,  1.2694198e-05],
   [ 2.1032608e+01,  3.0978260e+00,  8.1792423e-05],
   [ 3.2119564e+01,  5.9673912e+01, -4.8189460e-05],
   [ 1.5652174e+01,  2.0217392e+01, -1.2792133e-04],
   [ 3.2445652e+01,  5.9673912e+01, -1.1050291e-04],
   [ 1.5652174e+01,  2.0217392e+01, -4.2534582e-05],
   [ 3.2282608e+01,  5.9673912e+01, -3.9592214e-05],
   [ 3.2445652e+01,  5.9673912e+01, -1.2300081e-04],
   [ 3.2119564e+01,  5.9673912e+01,  1.3895029e-04],
   [ 3.2119564e+01,  5.9673912e+01,  4.5048160e-04],
   [ 3.2119564e+01,  5.9673912e+01,  2.8149947e-03],
   [ 3.2119564e+01,  5.9673912e+01,  2.4660570e-03],
   [ 3.2119564e+01,  5.9673912e+01,  1.1084687e-05],
   [ 1.8423914e+01,  2.5597826e+01,  2.7254851e-05],
   [ 1.8423914e+01,  2.5597826e+01,  4.5520133e-06],
   [ 3.5706520e+01,  1.5163043e+01,  1.3295857e-05],
   [ 3.2282608e+01,  5.9673912e+01,  4.1052594e-06],
   [ 3.2119564e+01,  5.9673912e+01,  5.6243367e-05],
   [ 3.3097828e+01,  5.8206520e+01,  2.3062130e-05],
   [ 3.2119564e+01,  5.9673912e+01,  6.7559289e-05],
   [ 3.2119564e+01,  5.9673912e+01,  6.5806766e-05],
   [ 3.2119564e+01,  5.9673912e+01,  9.2756242e-04],
   [ 3.2119564e+01,  5.9673912e+01,  5.2335125e-04],
   [ 3.2282608e+01,  5.9673912e+01,  3.2513806e-05],
   [ 1.8423914e+01,  2.5597826e+01,  1.3968185e-05],
   [ 3.2119564e+01,  5.9673912e+01,  1.5303758e-05],
   [ 1.6141304e+01,  2.1684782e+01,  1.7933089e-05],
   [ 3.2119564e+01,  5.9673912e+01,  6.1444991e-04],
   [ 2.1032608e+01,  3.0978260e+00,  2.0746856e-04],
   [ 1.5652174e+01,  2.0054348e+01, -9.7850330e-05]])
揽清风入怀 2025-01-25 02:23:34

嗯,据我了解,你想要一个二维数组,

所以阶段是:(

伪-python)

data=get string from "0.txt" file.read()..etc

line_splitted=data.split('\n') # split by lines

2d_array=[]

for line in line_splitted:
# this is the method:      * space split   *the 'replace's are to remove the brackets
   2d_array.append(  line.split(' ').replace("[","").replace("]","") )

return 2d_array # you may convert it to numpy now, its a list of lists (2d list) , 
# /!\ each element is in string form, gotta be converted to float as well

Well , as I understood it, you want a 2d array

so the stages are:

(pseudo - python)

data=get string from "0.txt" file.read()..etc

line_splitted=data.split('\n') # split by lines

2d_array=[]

for line in line_splitted:
# this is the method:      * space split   *the 'replace's are to remove the brackets
   2d_array.append(  line.split(' ').replace("[","").replace("]","") )

return 2d_array # you may convert it to numpy now, its a list of lists (2d list) , 
# /!\ each element is in string form, gotta be converted to float as well
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文