scikit-image转换ValueError:缓冲区不连续 [英] scikit-image transform ValueError: Buffer not C contiguous

查看:90
本文介绍了scikit-image转换ValueError:缓冲区不连续的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用skimage转换模块的resize方法.

I'm using the skimage transform module's resize method.

并非总是如此,但有时,我在这条线上出现错误:

Not always, but sometimes, I'm getting an error on this line:

candidate = resize(np.copy(img[candidate_box[0]:candidate_box[2],candidate_box[1]:candidate_box[3]]), (50,100))

它告诉我:

ValueError: Buffer not C contiguous

我该如何解决?

推荐答案

整形(和其他操作)有时会破坏数组的连续性.您可以通过查看flags:

Reshaping (and other operations) will sometimes disrupt the contiguity of an array. You can check whether this has happened by looking at the flags:

>>> a = np.arange(10).reshape(5, 2).T
>>> a.flags
  C_CONTIGUOUS : False # reshaped array is no longer C contiguous
  F_CONTIGUOUS : True
  OWNDATA : False
  WRITEABLE : True
  ALIGNED : True
  UPDATEIFCOPY : False

尝试使用 :

 >>> b = np.ascontiguousarray(a)
 >>> b.flags
  C_CONTIGUOUS : True # array b is a C contiguous copy of array a
  F_CONTIGUOUS : False
  OWNDATA : True
  WRITEABLE : True
  ALIGNED : True
  UPDATEIFCOPY : False

该函数返回一个形状和值与目标数组相同的数组,但返回的数组存储为C连续数组.

The function returns an array with the same shape and values as the target array, but the returned array is stored as a C contiguous array.

这篇关于scikit-image转换ValueError:缓冲区不连续的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆