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

本文档展示了如何使用Python读取指定目录下的bin文件,并通过比较文件路径来检查文件是否来源于同一父路径。它演示了如何将数据转换为数组并进行操作,以及简单的文件路径比较部分。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值