当前位置:   article > 正文

ImportError: cannot import name '_validate_lengths'

ImportError: cannot import name '_validate_lengths'

找到:Anaconda3/lib/python3.6/site-packages/numpy/lib/arraypad.py   954行,添加下面两个函数保存,重新加载即可消除错误 

  1. def _normalize_shape(ndarray, shape, cast_to_int=True):
  2. """
  3. Private function which does some checks and normalizes the possibly
  4. much simpler representations of ‘pad_width‘, ‘stat_length‘,
  5. ‘constant_values‘, ‘end_values‘.
  6. Parameters
  7. ----------
  8. narray : ndarray
  9. Input ndarray
  10. shape : {sequence, array_like, float, int}, optional
  11. The width of padding (pad_width), the number of elements on the
  12. edge of the narray used for statistics (stat_length), the constant
  13. value(s) to use when filling padded regions (constant_values), or the
  14. endpoint target(s) for linear ramps (end_values).
  15. ((before_1, after_1), ... (before_N, after_N)) unique number of
  16. elements for each axis where `N` is rank of `narray`.
  17. ((before, after),) yields same before and after constants for each
  18. axis.
  19. (constant,) or val is a shortcut for before = after = constant for
  20. all axes.
  21. cast_to_int : bool, optional
  22. Controls if values in ``shape`` will be rounded and cast to int
  23. before being returned.
  24. Returns
  25. -------
  26. normalized_shape : tuple of tuples
  27. val => ((val, val), (val, val), ...)
  28. [[val1, val2], [val3, val4], ...] => ((val1, val2), (val3, val4), ...)
  29. ((val1, val2), (val3, val4), ...) => no change
  30. [[val1, val2], ] => ((val1, val2), (val1, val2), ...)
  31. ((val1, val2), ) => ((val1, val2), (val1, val2), ...)
  32. [[val , ], ] => ((val, val), (val, val), ...)
  33. ((val , ), ) => ((val, val), (val, val), ...)
  34. """
  35. ndims = ndarray.ndim
  36. # Shortcut shape=None
  37. if shape is None:
  38. return ((None, None), ) * ndims
  39. # Convert any input `info` to a NumPy array
  40. shape_arr = np.asarray(shape)
  41. try:
  42. shape_arr = np.broadcast_to(shape_arr, (ndims, 2))
  43. except ValueError:
  44. fmt = "Unable to create correctly shaped tuple from %s"
  45. raise ValueError(fmt % (shape,))
  46. # Cast if necessary
  47. if cast_to_int is True:
  48. shape_arr = np.round(shape_arr).astype(int)
  49. # Convert list of lists to tuple of tuples
  50. return tuple(tuple(axis) for axis in shape_arr.tolist())
  51. def _validate_lengths(narray, number_elements):
  52. """
  53. Private function which does some checks and reformats pad_width and
  54. stat_length using _normalize_shape.
  55. Parameters
  56. ----------
  57. narray : ndarray
  58. Input ndarray
  59. number_elements : {sequence, int}, optional
  60. The width of padding (pad_width) or the number of elements on the edge
  61. of the narray used for statistics (stat_length).
  62. ((before_1, after_1), ... (before_N, after_N)) unique number of
  63. elements for each axis.
  64. ((before, after),) yields same before and after constants for each
  65. axis.
  66. (constant,) or int is a shortcut for before = after = constant for all
  67. axes.
  68. Returns
  69. -------
  70. _validate_lengths : tuple of tuples
  71. int => ((int, int), (int, int), ...)
  72. [[int1, int2], [int3, int4], ...] => ((int1, int2), (int3, int4), ...)
  73. ((int1, int2), (int3, int4), ...) => no change
  74. [[int1, int2], ] => ((int1, int2), (int1, int2), ...)
  75. ((int1, int2), ) => ((int1, int2), (int1, int2), ...)
  76. [[int , ], ] => ((int, int), (int, int), ...)
  77. ((int , ), ) => ((int, int), (int, int), ...)
  78. """
  79. normshp = _normalize_shape(narray, number_elements)
  80. for i in normshp:
  81. chk = [1 if x is None else x for x in i]
  82. chk = [1 if x >= 0 else -1 for x in chk]
  83. if (chk[0] < 0) or (chk[1] < 0):
  84. fmt = "%s cannot contain negative values."
  85. raise ValueError(fmt % (number_elements,))
  86. return normshp
  87. ###############################################################################
  88. # Public functions​

原文链接:http://www.bubuko.com/infodetail-2921218.html

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/657812
推荐阅读
相关标签
  

闽ICP备14008679号