简体   繁体   English

零大小数组到没有标识的最大归约操作

[英]zero-size array to reduction operation maximum which has no identity

Here is a runnable snippet of code which generates the error on my machine.这是一个可运行的代码片段,它在我的机器上生成错误。 I have this error (zero-size array to reduction operation maximum which has no identity).我有这个错误(零大小数组到减少操作最大值,没有标识)。

reader = csv.reader(open(BASE_PATH + 'labels.csv'))
# skip the header
next(reader)

X = []
y = []

for row in reader:
    label = row[2]
    if len(label) > 0 and label.find(',') == -1:
        filename = get_filename_for_index(row[1])
        img_file = cv2.imread(BASE_PATH + filename)
        if img_file is not None:
            img_file = scipy.misc.imresize(arr=img_file, size=(120, 160, 3))
            img_arr = np.asarray(img_file)
            img_arr = apply_color_mask(img_arr)
            X.append(img_arr)
            y.append(label)


X = np.asarray(X)
y = np.asarray(y)

encoder = LabelEncoder()
encoder.fit(y)
encoded_y = encoder.transform(y)

y = np_utils.to_categorical(encoded_y)


**Error**
ValueError                                Traceback (most recent call last)
<ipython-input-7-49c49b99292b> in <module>()
     26 encoded_y = encoder.transform(y)
     27 
---> 28 y = np_utils.to_categorical(encoded_y)

~/.local/lib/python3.5/site-packages/keras/utils/np_utils.py in to_categorical(y, num_classes)
     20     y = np.array(y, dtype='int').ravel()
     21     if not num_classes:
---> 22         num_classes = np.max(y) + 1
     23     n = y.shape[0]
     24     categorical = np.zeros((n, num_classes))

~/.local/lib/python3.5/site-packages/numpy/core/fromnumeric.py in amax(a, axis, out, keepdims)
   2270 
   2271     return _methods._amax(a, axis=axis,
-> 2272                           out=out, **kwargs)
   2273 
   2274 

~/.local/lib/python3.5/site-packages/numpy/core/_methods.py in _amax(a, axis, out, keepdims)
     24 # small reductions
     25 def _amax(a, axis=None, out=None, keepdims=False):
---> 26     return umr_maximum(a, axis, None, out, keepdims)
     27 
     28 def _amin(a, axis=None, out=None, keepdims=False):

Value Error: zero-size array to reduction operation maximum which has no identity值错误:零大小数组到没有标识的缩减操作最大值

so please any one can help me.所以请任何人都可以帮助我。

You can try to put the failing operation inside some kind guard:您可以尝试将失败的操作置于某种保护之下:

if np.any(encoded_y):
    y = np_utils.to_categorical(encoded_y)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 零大小数组到没有标识的缩减操作 fmin - zero-size array to reduction operation fmin which has no identity 零大小数组到最大归约操作,对于多输出 U-net 没有标识 - zero-size array to reduction operation maximum which has no identity for multi output U-net 具有Statsmodel ValueError的多个OLS回归:零大小数组到减少操作最大值,没有标识 - Multiple OLS Regression with Statsmodel ValueError: zero-size array to reduction operation maximum which has no identity 如何修复 keras pad_sequences 中的“零大小数组到没有标识的最大缩减操作” - How to fix "zero-size array to reduction operation maximum which has no identity" in keras pad_sequences SciPy optimize.fmin ValueError:零大小数组到减少操作最大值,没有标识 - SciPy optimize.fmin ValueError: zero-size array to reduction operation maximum which has no identity OLS回归存储问题:零大小数组到归约操作最大值,没有身份 - OLS regression storing problem: zero-size array to reduction operation maximum which has no identity 如何将 np.max 用于没有 ValueError 的空 numpy 数组:零大小数组到没有标识的缩减操作最大值 - how to use np.max for empty numpy array without ValueError: zero-size array to reduction operation maximum which has no identity 为什么我会得到以及如何解决 ValueError: zero-size array to reduction operation maximum which has no identity - Why am I getting and how to solve ValueError: zero-size array to reduction operation maximum which has no identity 如何修复&#39;ValueError:零尺寸数组到没有身份的归约运算fmin&#39; - How to fix 'ValueError: zero-size array to reduction operation fmin which has no identity' ValueError:零大小数组到没有标识的最小化操作 - ValueError: zero-size array to reduction operation minimum which has no identity
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM