Python ValueError:无法将大小为 30470400 的数组重塑为形状 (50,1104,104)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42947298/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 22:18:15  来源:igfitidea点击:

ValueError: cannot reshape array of size 30470400 into shape (50,1104,104)

pythonnumpyreshape

提问by Bananaboy99

I am trying to run threw this Tutorial http://emmanuelle.github.io/segmentation-of-3-d-tomography-images-with-python-and-scikit-image.html

我试图运行抛出这个教程 http://emmanuelle.github.io/segmentation-of-3-d-tomography-images-with-python-and-scikit-image.html

where I want to do a Segmentation of 3-D tomography images with Python.

我想用 Python 对 3-D 断层扫描图像进行分割。

I'm struggling directly in the beginning, with reshaping the image.

我一开始就直接在挣扎,重塑形象。

This is the code:

这是代码:

%matplotlib inline

import numpy as np

import matplotlib.pyplot as plt 

import time as time 

data = np.fromfile('/data/data_l67/dalladas/Python3/Daten/Al8Cu_1000_g13_t4_200_250.vol', dtype=np.float32)

data.shape

(60940800,)

data.reshape((50,1104,104))

--------------------------------------------------------------------------- ValueError Traceback (most recent call last) in () ----> 1 data.reshape((50,1104,104))

ValueError: cannot reshape array of size 30470400 into shape (50,1104,104)

-------------------------------------------------- ------------------------- ValueError Traceback (最近一次调用最后一次) in () ----> 1 data.reshape((50,1104 ,104))

ValueError:无法将大小为 30470400 的数组重塑为形状 (50,1104,104)

Can somebody help me out?

有人可以帮我吗?

回答by Miriam Farber

It seems that there is a typo, since 1104*1104*50=60940800and you are trying to reshape to dimensions 50,1104,104. So it seems that you need to change 104 to 1104.

似乎有一个错字,因为1104*1104*50=60940800你正试图重塑到维度50,1104,104。所以看起来你需要把104改成1104。

回答by ajithvd

data.reshape((50,1104,-1))

works for me

为我工作

回答by NSVR

In Matrix terms no of elements always equal to product of no of rows and columns. Here this condition is not matching

在矩阵术语中,元素数总是等于行数和列数的乘积。这里这个条件不匹配