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.  
  52. def _validate_lengths(narray, number_elements):

  53. """

  54. Private function which does some checks and reformats pad_width and

  55. stat_length using _normalize_shape.

  56. Parameters

  57. ----------

  58. narray : ndarray

  59. Input ndarray

  60. number_elements : {sequence, int}, optional

  61. The width of padding (pad_width) or the number of elements on the edge

  62. of the narray used for statistics (stat_length).

  63. ((before_1, after_1), ... (before_N, after_N)) unique number of

  64. elements for each axis.

  65. ((before, after),) yields same before and after constants for each

  66. axis.

  67. (constant,) or int is a shortcut for before = after = constant for all

  68. axes.

  69. Returns

  70. -------

  71. _validate_lengths : tuple of tuples

  72. int => ((int, int), (int, int), ...)

  73. [[int1, int2], [int3, int4], ...] => ((int1, int2), (int3, int4), ...)

  74. ((int1, int2), (int3, int4), ...) => no change

  75. [[int1, int2], ] => ((int1, int2), (int1, int2), ...)

  76. ((int1, int2), ) => ((int1, int2), (int1, int2), ...)

  77. [[int , ], ] => ((int, int), (int, int), ...)

  78. ((int , ), ) => ((int, int), (int, int), ...)

  79. """

  80. normshp = _normalize_shape(narray, number_elements)

  81. for i in normshp:

  82. chk = [1 if x is None else x for x in i]

  83. chk = [1 if x >= 0 else -1 for x in chk]

  84. if (chk[0] < 0) or (chk[1] < 0):

  85. fmt = "%s cannot contain negative values."

  86. raise ValueError(fmt % (number_elements,))

  87. return normshp

  88. ###############################################################################

  89. # Public functions​

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值