gpt4 book ai didi

java - Java中的ShortBuffer和矩阵

转载 作者:行者123 更新时间:2023-12-01 15:39:04 26 4
gpt4 key购买 nike

我在使用 ShortBuffer 时遇到问题。这是我的代码:

FileChannel fc = new FileInputStream("C:/Dane DMS/"+names2).getChannel();
ByteBuffer bb = ByteBuffer.allocateDirect((int) fc.size());
while (bb.remaining() > 0) fc.read(bb);
fc.close();
bb.flip();
// choose the right endianness
ShortBuffer sb = bb.order(ByteOrder.BIG_ENDIAN).asShortBuffer();

在这个文件中我有一个矩阵。

111 222 333 123
444 555 666 456
777 888 999 789
098 765 432 321

我需要将此矩阵更改为:

098 765 432 321
777 888 999 789
444 555 666 456
111 222 333 123

我必须更改此矩阵或创建从数字 098 开始到数字 123 结束的循环。

我不打印这个矩阵。我正在使用:

for(int i = 0; i<=1200; i++)
{
for(int j = 0; j<=1200 ; j++)
{

}

}

到交叉矩阵,但这样我从数字 111 开始,我需要从 098 开始到 123 结束。

最佳答案

你可以试试这个

FileChannel fc = new FileInputStream("C:/Dane DMS/"+names2).getChannel();
ByteBuffer bb = ByteBuffer.allocateDirect((int) fc.size());
while (bb.remaining() > 0) fc.read(bb);
fc.close();
bb.flip();
// choose the right endianness
ShortBuffer sb = bb.order(ByteOrder.BIG_ENDIAN).asShortBuffer();

short[][] Matrix = new short[1201][1201];
for(int i = 0; i<=1200; i++)
{
for(int j = 0; j<=1200 ; j++)
{
Matrix[1200-i][j] = sb.get(i*1201+j);
}
}

关于java - Java中的ShortBuffer和矩阵,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8374454/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com