我在 python 中创建了一个名为 random_from_python_int.dat 的 5*7 整数矩阵二进制文件,然后我从 C 中读取了这个二进制文件。不知何故我无法得到正确的数字这是我生成这个矩阵的 python 代码:
import numpy as np
np.random.seed(10)
filename = "random_from_python_int.dat"
fileobj = open(filename, mode='wb')
b = np.random.randint(100, size=(5,7))
b.tofile(fileobj)
fileobj.close
Run Code Online (Sandbox Code Playgroud)
这将生成一个矩阵
[ [ 9 15 64 28 89 93 29]
[ 8 73 0 40 36 16 11]
[ 54 88 62 33 72 78 49]
[ 51 54 77 69 13 25 13]
[ 92 86 30 30 89 12 65] ]
Run Code Online (Sandbox Code Playgroud)
但是当我从下面的 C 代码中读取它时:
#include <stdio.h>
#include <math.h>
int …Run Code Online (Sandbox Code Playgroud)