相关疑难解决方法(0)

在Python中,如果我在"with"块内返回,文件是否仍会关闭?

考虑以下:

with open(path, mode) as f:
    return [line for line in f if condition]
Run Code Online (Sandbox Code Playgroud)

文件是否会正确关闭,或者以return某种方式绕过上下文管理器?

python return with-statement

222
推荐指数
4
解决办法
4万
查看次数

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

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

我想用Python进行三维断层扫描图像分割.

我在开始时直接挣扎,重塑了形象.

这是代码:

%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))
Run Code Online (Sandbox Code Playgroud)

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

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

有人可以帮帮我吗?

python numpy reshape

7
推荐指数
3
解决办法
7万
查看次数

标签 统计

python ×2

numpy ×1

reshape ×1

return ×1

with-statement ×1