python----read bin and compare t/f

import os
import numpy as np

path = "/home/linux/1.bin"#bin
s = []  #
t = []
n = []
folders = [os.path.join(path, i) for i in os.listdir(path)]
for info in folders:
    files = os.listdir(info)
    for file in files:
        if file.endswith("bin"):
            a = np.fromfile(info + "/" + file, dtype=np.float32)  # read bin
            # a = np.fromfile(info + "/" + file, dtype=np.int8)  # test
            a1 = info + "/" + file
            s.append(a)
            t.append(a1)
            a2=file
            a3=a2[:-4]
            n.append(a3)
    # s1 = np.array(s)
# print(s1)
#------save----path-----
# file = open('path.txt', 'w')
# for i in range(len(t)):
#     s = str(t[i]).replace('{', '').replace('}', '').replace("'", '').replace(':', ',') + '\n'
#     file.write(s)
# file.close()
#------save----path-----end-----
#------save----id_name-----
# file = open('id_name.txt', 'w')
# for i in range(len(n)):
#     s = str(n[i]) + '\n'
#     file.write(s)
# file.close()
#------save----id_name----end----
# c = torch.Tensor(s1)
# d = c.reshape(20, 128)  #

# s1 = [token for st in s for token in st]
s1 = np.asarray(s)
# -------------------compare----t-or-f---s1--------
relist =[]
t1 = t[0::2]
t2 = t[1::2]
for i in range(2):#
    t11 = t1[i]
    last_index = t11.rfind('/')
    t11 = t11[0:last_index]
    t12 = t2[i]
    last_index = t12.rfind('/')
    t12 = t12[0:last_index]
    ysame = os.path.samefile(t11, t12)#
    relist.append(ysame)
# print(relist)

猜你喜欢

转载自blog.csdn.net/qq_43508270/article/details/127468895