You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Numpy Memmap遇WinError8求助:读取raw byte文件转为指定数组

解决Raw Byte文件读取为指定形状Fortran序数组的问题

Hey there! First off, huge kudos for finally joining the conversation after six years of using Stack Overflow—we’re stoked you’re reaching out with your question. Let’s get this raw file sorted out for you.

First, let’s confirm the numbers check out: your target shape (613, 640, 224) has a total of 613 * 640 * 224 = 87,879,680 elements. Since each np.uint16 takes up 2 bytes, that’s exactly 87,879,680 * 2 = 175,759,360 bytes—matching your file size perfectly. That’s a good start!

Here’s a straightforward Python/Numpy workflow to read your file into the desired array:

import numpy as np

# Replace with your actual file path
raw_file_path = "your_file.raw"

# Step 1: Read the raw bytes directly as uint16 values
raw_data = np.fromfile(raw_file_path, dtype=np.uint16)

# Quick sanity check to ensure we have the right number of elements
assert raw_data.size == 613 * 640 * 224, "File size doesn't match the target shape's element count!"

# Step 2: Reshape into the Fortran-ordered array
target_array = raw_data.reshape((613, 640, 224), order='F')

# Optional: Verify the array is indeed Fortran-contiguous
print(f"Array is Fortran-ordered: {target_array.flags.f_contiguous}")

A few troubleshooting tips if things go sideways:

  • Double-check your file path: It’s easy to accidentally point to the wrong directory or a corrupted copy of the file.
  • Confirm the file size hasn’t changed: Use os.path.getsize(raw_file_path) to ensure it’s still 175759360 bytes.
  • If your data looks garbled after reading, try adjusting the reshape order or transposing: Sometimes raw files might be stored in a different implicit order. For example, you could try reshaping to (224, 640, 613) with order='C' then transposing to (613, 640, 224)—though the first method should work if your original successful runs used Fortran order.

Let me know if you hit any specific snags—like weird data values or shape errors—and we can troubleshoot further!

内容的提问来源于stack exchange,提问作者Urban Avsec

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 11:35:14