##配列の要素を入れ替えたいです
Pythonで書かれたコードでの添え字の[:, :, 0]の意味がわかりません。
C#だと添え字は何と書けばいいでしょうか?教えてください。
0番目の要素と、2番目の要素を入れ替える
Python
1 # 配列の形状変換。 2 # 1つの要素がRGBAである、height * widthの行列を作る。 3 img = numpy.reshape(tmp, (height, wigth, 4)) 4 5 b = img[:, :, 0].copy() # ここのコピーも必須 6 img[:, :, 0] = img[:, :, 2] 7 img[:, :, 2] = b 8引用元:https://qiita.com/frameair/items/0c8113c716f87ccb8a37
C#
1using (Stream stream = Comannd("exec-out screencap")) 2 { 3 /* 4 1~4byte 4byte width 5 5~8byte 4byte height 6 9~12byte 4byte pixelformat 7 13byte~ 画素。RGBA順に並んでおり、4byteで1ピクセル 8 */ 9 using(MemoryStream ms = new MemoryStream()) 10 { 11 stream.CopyTo(ms); 12 byte[] buf = ms.ToArray(); 13 14 ms.Position = 13; 15 ms.Read(buf, 0, buf.Length -13); 16 17 NDArray img = np.reshape(buf, (1080, 2340, 4)); 18 img[????] 19 20 } 21 } 22 23static Stream Comannd(string comannd) 24 { 25 using (var pro = new Process()) 26 { 27 var startInfo = new ProcessStartInfo() 28 { 29 FileName = @"C:\Users\hoge\Documents\Zips\platform-tools\adb.exe", 30 Arguments = comannd, 31 CreateNoWindow = true, 32 UseShellExecute = false, 33 RedirectStandardOutput = true, 34 }; 35 pro.StartInfo = startInfo; 36 pro.Start(); 37 pro.WaitForExit(3000); 38 return pro.StandardOutput.BaseStream; 39 } 40 }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2020/01/14 10:27
退会済みユーザー
2020/01/14 13:21