此代码中的Python ValueError

时间:2017-04-21 10:13:51

标签: python numpy

追踪(最近一次呼叫最后一次):

<!doctype html>
<html>
<head>
<title>Node Authentication</title>
<link rel="stylesheet"   href="//netdna.bootstrapcdn.com/bootstrap/3.0.2/css/bootstrap.min.css">    <!-- load bootstrap css -->
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.min.css"> <!-- load fontawesome -->
<style>
    body        { padding-top:80px; }
</style>
</head>
<body>
<div class="container">

<div class="col-sm-6 col-sm-offset-3">

<h1><span class="fa fa-sign-in"></span> Signup</h1>
<!-- show any messages that come back with authentication -->
<% if (message.length > 0) { %>
    <div class="alert alert-danger"><%= message %></div>
<% } %>

<!-- LOGIN FORM -->
<form action="/signup" method="post">
    <div class="form-group">
        <label>Email</label>
        <input type="text" class="form-control" name="email">
    </div>
    <div class="form-group">
        <label>Password</label>
        <input type="password" class="form-control" name="password">
    </div>

    <button type="submit" class="btn btn-warning btn-lg">Signup</button>
</form>

<hr>

<p>Already have an account? <a href="/login">Login</a></p>
<p>Or go <a href="/">home</a>.</p>

</div>

</div>
</body>
</html>

  File "project.py", line 35, in <module>
    cells = [np.hsplit(row,100) for row in np.vsplit(img,50)]
  File "/usr/local/lib/python2.7/site-packages/numpy/lib/shape_base.py", line 623, in vsplit
    return split(ary, indices_or_sections, 0)
  File "/usr/local/lib/python2.7/site-packages/numpy/lib/shape_base.py", line 508, in split
    'array split does not result in an equal division')
ValueError: array split does not result in an equal division

2 个答案:

答案 0 :(得分:1)

从错误和代码搜索(对于`拆分),错误必须在

中发生
[np.hsplit(row,100) for row in np.vsplit(img,50)]

img的形状是什么?该错误表明它(img.shape[0])不是50的倍数。

答案 1 :(得分:0)

您可能试图将矢量分解为线条。但是,请确保向量的元素数量是您尝试将其分解的行数的倍数。例如,您不能将(5,1)向量拆分为2行。在这种情况下,每个row的大小必须是100的倍数。

相关问题