(1)打开mat

import numpy as np
import scipy.io as sio

# for i in range(2,50):
#
#
#     filename = "simsTxt/sim100_sub{}.mat".format(i)
#     matdata = sio.loadmat(filename)
#     data = matdata["BOLD"].tolist()
#     save_path = "simsTxt/sim100_sub{}.txt".format(i)
#
#     def remove_parentheses(value):
#         value = str(value).replace('(', '').replace(')', '')
#         return value
#
#     with open(save_path, 'w') as file:
#         for row in data:
#             line = '\t'.join(map(remove_parentheses, row))
#             file.write(line + '\n')

filename = r"sim1.mat"
matdata = sio.loadmat(filename)
data = matdata["net"].tolist()
save_path = r"sim1.txt"

def remove_parentheses(value):
    value = str(value).replace('(', '').replace(')', '')
    return value

with open(save_path, 'w') as file:
    for row in data:
        line = '\t'.join(map(remove_parentheses, row))
        file.write(line + '\n')

(2)打开csv

import pandas as pd
X = pd.read_csv(file_path, header=None).to_numpy()

(3)打开txt

import numpy as np
X = np.loadtxt(file_path)
Logo

开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!

更多推荐