0

.npz file contains two npy files, faces.npy and neighbors.npy.

  • faces.npy is float64, shape is 12*15
  • neighbors.npy is int64, shape is 12*3

First try: Type is double[,], but neighbors is null

var npz = np.Load_Npz<double[,]>(@"D:\dnns\ifcnet\test\wall\IFCWALL.43.npz");
var faces = npz["faces.npy"];
var neighbors = npz["neighbors.npy"];

Second try: Type is Int64[,], but faces is null

var npz = np.Load_Npz<In[,]>(@"D:\dnns\ifcnet\test\wall\IFCWALL.43.npz");
var faces = npz["faces.npy"];
var neighbors = npz["neighbors.npy"];

Third try: Read faces by double[,], and read neighbors by Int64[,], but when reading the same file, another process uses the file!

var npz = np.Load_Npz<double[,]>(@"D:\dnns\ifcnet\test\wall\IFCWALL.43.npz");
var faces = npz["faces.npy"];
var npz2 = np.Load_Npz<Int64[,]>(@"D:\dnns\ifcnet\test\wall\IFCWALL.43.npz");
var neighbors= npz2["neighbors.npy"];
YukiNyaa
  • 136
  • 1
  • 13

2 Answers2

0

My speculation is that loading NPZ with multiple type is not supported.

My approach to this problem is to load NPZ file as ZipArchive, then open the stream, then feed it to the load function.

using (ZipArchive archive = new ZipArchive(new FileStream(fileName, FileMode.Open)))
{
    Stream transStream = archive.GetEntry("trans.npy").Open();
    NDArray npyContent = np.load(transStream);
}

Notice that I use load instead of Load<T>. This way, you can load multiple types of arrays without prior knowledge of the array.

Note: Load<float[,]> fails with some random files, but load worked reliably.

YukiNyaa
  • 136
  • 1
  • 13
0

Try this:

var npz = np.Load_Npz<Array>(@"D:\dnns\ifcnet\test\wall\IFCWALL.43.npz");
var faces = npz["faces.npy"];
var neighbors = npz["neighbors.npy"];

This returns NpzDictionary<T> (or NpzDictionary<Array>), which your npz["faces.npy"] will then convert to an [,] array.

Alex R.
  • 644
  • 6
  • 9