在 python 中打开一个 .mat 文件以便在 matlab 中使用
opening a .mat file in python for using in matlab
我正在尝试打开文件名为 MNIST.mat 的 .MAT 文件,它位于以下文件夹中
/home/debian/cs640 机器 learning/assignment5
这是我在互联网上搜索后编写的脚本我想做的是打开文件并将其另存为 excel
#!/usr/bin/python3
import os
from mat4py import loadmat
os.getcwd()
mat=loadmat('/home/debian/cs640 machine learning/assignment5\MNIST.mat')
print (mat)
~
但目前我收到错误
Traceback (most recent call last): File "./script1.py", line 5, in
mat=loadmat('/home/debian/cs640 machine learning/assignment5\MNIST.mat') File
"/home/debian/.local/lib/python3.7/site-packages/mat4py/loadmat.py",
line 417, in loadmat
fd = open(filename, 'rb') FileNotFoundError: [Errno 2] No such file or directory: '/home/debian/cs640 machine
learning/assignment5\MNIST.mat'
为什么我的程序会出现这个错误?
程序找不到文件。检查文件的路径或名称。
您的目录名称 cs640 机器学习中有 space。将其更改为 cs640_machine_learning。可能有用。
您混淆了 Unix 和 DOS 目录分隔符。您正在使用 Linux,它使用 Unix 风格的 /
作为目录分隔符。 Windows 使用 DOS 风格的 \
作为目录分隔符。您的文件位置混合了两者。只需更改:
'assignment5\MNIST.mat'
至
'assignment5/MNIST.mat'
我正在尝试打开文件名为 MNIST.mat 的 .MAT 文件,它位于以下文件夹中 /home/debian/cs640 机器 learning/assignment5 这是我在互联网上搜索后编写的脚本我想做的是打开文件并将其另存为 excel
#!/usr/bin/python3
import os
from mat4py import loadmat
os.getcwd()
mat=loadmat('/home/debian/cs640 machine learning/assignment5\MNIST.mat')
print (mat)
~
但目前我收到错误
Traceback (most recent call last): File "./script1.py", line 5, in mat=loadmat('/home/debian/cs640 machine learning/assignment5\MNIST.mat') File "/home/debian/.local/lib/python3.7/site-packages/mat4py/loadmat.py", line 417, in loadmat fd = open(filename, 'rb') FileNotFoundError: [Errno 2] No such file or directory: '/home/debian/cs640 machine learning/assignment5\MNIST.mat'
为什么我的程序会出现这个错误?
程序找不到文件。检查文件的路径或名称。 您的目录名称 cs640 机器学习中有 space。将其更改为 cs640_machine_learning。可能有用。
您混淆了 Unix 和 DOS 目录分隔符。您正在使用 Linux,它使用 Unix 风格的 /
作为目录分隔符。 Windows 使用 DOS 风格的 \
作为目录分隔符。您的文件位置混合了两者。只需更改:
'assignment5\MNIST.mat'
至
'assignment5/MNIST.mat'