简体   繁体   English

预期 2D 数组,得到 1D 数组:array=[5.6 7. ]。 使用 array.reshape(-1, 1) 重塑数据

[英]Expected 2D array, got 1D array instead: array=[5.6 7. ]. Reshape your data either using array.reshape(-1, 1)

when we found value through the predict but i received an error当我们通过预测找到价值但我收到一个错误

"Expected 2D array, got 1D array instead:
array=[5.6 7. ].
Reshape your data either using array.reshape(-1, 1) if your data has a 
  single feature or array.reshape(1, -1) if it contains a single sample."

this is error plzz solve my problem it's very complicated error that's why i haven't received error solution这是错误请解决我的问题这是非常复杂的错误这就是为什么我没有收到错误解决方案

You just printed the error, But error itself gave the solution.您刚刚打印了错误,但错误本身给出了解决方案。

In case function accepts only 2 D array, then any numpy.ndarray can be converted to the 2 array by reshaping it by numpy.reshape(arr, (1, -1).如果 function 仅接受 2 D 数组,则任何numpy.ndarray都可以通过 numpy.reshape(

Now please observe the effect of reshape opperation, Here (1, -1) , first 1 represent the first dimension of array, -1 represent or just use for flattening the array, in case you have array with dimension greater than 2.现在请观察 reshape 操作的效果,这里(1, -1) ,前1表示数组的第一个维度, -1表示或仅用于扁平化数组,以防您有维度大于 2 的数组。

For 1-D array you can also use (1, len(arr))对于一维数组,您还可以使用(1, len(arr))

import numpy
arr = = numpy.array([1, 3, 5, 6, 7, 8, 8])
numpy.reshape(arr, (1, -1))
numpy.reshaoe(arr, (1, len(arr)))

both reshaping has same result.两种重塑都有相同的结果。 Output Output

>>> array([[1, 3, 5, 6, 7, 8, 8]])  # output of numpy.reshape(arr, (1, -1))
>>> array([[1, 3, 5, 6, 7, 8, 8]])  # output of numpy.reshape(arr, (1, len(arr)))

So reshaping makes your array compatible with the function which you are using, but in case function excepts 2D and you are having 1D array, there should be some meaningful way to transform your 1-D thing to 2-D.因此,重塑使您的阵列与您正在使用的 function 兼容,但如果 function 不包括 2D 并且您拥有 1D 阵列,则应该有一些有意义的方法将您的 1-D 事物转换为 2-D。

Means if function accepts 2D image, and you have 1D audio sequence, there really should meaning full way to transform.意味着如果 function 接受 2D 图像,并且您有 1D 音频序列,那么确实应该有完整的转换方式。

If you could have also mention that, help will true help.如果您也可以提及,帮助将是真正的帮助。 For now we are guessing on our mind thought what you need.现在,我们正在猜测我们的想法认为您需要什么。

So always before asking question please spent some time in framing question, so getting answer and getting issue solved is guaranteed所以总是在提问之前请花一些时间来构思问题,这样可以保证得到答案并解决问题

暂无
暂无

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

相关问题 ValueError:预期的 2D 数组,得到 1D 数组:array=[19. 27.896 0. 1. 0. ]。 使用 array.reshape(-1, 1) 重塑数据 - ValueError: Expected 2D array, got 1D array instead: array=[19. 27.896 0. 1. 0. ]. Reshape your data either using array.reshape(-1, 1) 这是什么原因:'ValueError: Expected 2D array, got 1D array instead: & reshape your data using array.reshape(-1, 1)'? - what's the reasons about this:'ValueError: Expected 2D array, got 1D array instead: & reshape your data using array.reshape(-1, 1)'? 使用 array.reshape(-1, 1) python 重塑数据 - Reshape your data either using array.reshape(-1, 1) python 预期的二维数组,取而代之的是一维数组,重塑数据 - Expected 2D array, got 1D array instead, Reshape Data sklearn:使用 array.reshape(-1, 1) 如果您的数据具有单个特征或使用 array.reshape(1, -1) 如果它包含单个样本来重塑您的数据 - sklearn: Reshape your data either using array.reshape(-1, 1) if your data has a single feature or array.reshape(1, -1) if it contains a single sample 如果您的数据具有单个特征,则使用 array.reshape(-1, 1) 重塑您的数据,如果它包含单个样本,则使用 array.reshape(1, -1) - Reshape your data either using array.reshape(-1, 1) if your data has a single feature or array.reshape(1, -1) if it contains a single sample 如果数据具有单个功能,则可以使用array.reshape(-1,1)重塑数据 - Reshape your data either using array.reshape(-1, 1) if your data has a single feature 预期的二维数组,得到的是一维数组:array=[1 3 5 6 7 8 9]? - Expected 2D array, got 1D array instead: array=[1 3 5 6 7 8 9]? 预期的2D阵列,改为1D阵列 - Expected 2D array, got 1D array instead "预期的二维数组,得到一维数组而不是错误" - Expected 2D array, got 1D array instead error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM