static void SkapaNpzFil(List <OmniArtikel> artiklar, string path) { using (var stream = File.OpenWrite(path + "x_train.npy")) { var arrayList = new List <int[]>(); foreach (var artikel in artiklar) { arrayList.Add(TextTillIndexArray(artikel.Text.Trim())); } var yttreArray = arrayList.ToArray(); NpyFormat.Save(arrayList[0], stream); } using (var stream2 = File.OpenWrite(path + "x_test.npy")) { var arrayList = new List <int[]>(); foreach (var artikel in artiklar) { arrayList.Add(TextTillIndexArray(artikel.Text.Trim())); } var yttreArray = arrayList.ToArray(); NpyFormat.Save(arrayList[1], stream2); } var npyFiler = new List <string>(); npyFiler.Add(path + "x_train.npy"); npyFiler.Add(path + "x_test.npy"); var arrayList2 = new List <int[]>(); foreach (var artikel in artiklar) { arrayList2.Add(TextTillIndexArray(artikel.Text.Trim())); } var dict = new Dictionary <string, Array>(); dict.Add("x_train.npy", arrayList2[0]); dict.Add("x_test.npy", arrayList2[1]); using (var stream3 = File.OpenWrite(path + "omni_data.npz")) { NpzFormat.Save(dict, stream3, System.IO.Compression.CompressionLevel.Fastest); } }
public void WriteStringJaggedVariableColsTrimTest_Compressed() { string[][] value = { new[] { "a", "b" }, new[] { "d", "cs", "f"}, new[] { "z" }, }; byte[] bytes = NpzFormat.Save(value); string[][] expectedJagged = { new[] { "a", "b" }, new[] { "d", "cs", "f"}, new[] { "z" }, }; var arrJagged = NpzFormat.Load <string[][]>(bytes); string[][] actualJagged = arrJagged["arr_0"]; Assert.IsTrue(actualJagged.IsEqual(expectedJagged)); string[,] expectedMatrix = { { "a", "b", null }, { "d", "cs", "f" }, { "z", null, null }, }; var arrMatrix = NpzFormat.Load <string[, ]>(bytes); string[,] actualMatrix = arrMatrix["arr_0"]; Assert.IsTrue(actualJagged.IsEqual(expectedJagged)); }