ValueError: Length of values (1) does not match length of index (1024)

Viewed 50
import pickle
import numpy as np
import matplotlib.pyplot as plt

img = np.reshape(train.iloc[0],(1,32,32)) # get the first element from list

# inorder to view in imshow we need image of type (height,width, channel) rather than (channel, height,width)
imgView=np.transpose(img, (1,2,0))

plt.imshow(imgView)

**

ValueError                                Traceback (most recent call last)
Input In [41], in <cell line: 8>()
      5 import numpy as np
      6 import matplotlib.pyplot as plt
----> 8 img = np.reshape(train.iloc[0],(1,32,32)) # get the first element from list
     10 # inorder to view in imshow we need image of type (height,width, channel) rather than (channel, height,width)
     11 imgView=np.transpose(img, (1,2,0))
File <__array_function__ internals>:180, in reshape(*args, **kwargs)
File ~\AppData\Local\Programs\Python\Python310\lib\site-packages\numpy\core\fromnumeric.py:298, in reshape(a, newshape, order)
    198 @array_function_dispatch(_reshape_dispatcher)
    199 def reshape(a, newshape, order='C'):
    200     """
    201     Gives a new shape to an array without changing its data.
    202 
   (...)
    296            [5, 6]])
    297     """
--> 298     return _wrapfunc(a, 'reshape', newshape, order=order)
File ~\AppData\Local\Programs\Python\Python310\lib\site-packages\numpy\core\fromnumeric.py:54, in _wrapfunc(obj, method, *args, **kwds)
     52 bound = getattr(obj, method, None)
     53 if bound is None:
---> 54     return _wrapit(obj, method, *args, **kwds)
     56 try:
     57     return bound(*args, **kwds)
File ~\AppData\Local\Programs\Python\Python310\lib\site-packages\numpy\core\fromnumeric.py:47, in _wrapit(obj, method, *args, **kwds)
     45     if not isinstance(result, mu.ndarray):
     46         result = asarray(result)
---> 47     result = wrap(result)
     48 return result
File ~\AppData\Local\Programs\Python\Python310\lib\site-packages\pandas\core\generic.py:2095, in NDFrame.__array_wrap__(self, result, context)
   2093     return res
   2094 d = self._construct_axes_dict(self._AXIS_ORDERS, copy=False)
-> 2095 return self._constructor(res, **d).__finalize__(self, method="__array_wrap__")
File ~\AppData\Local\Programs\Python\Python310\lib\site-packages\pandas\core\series.py:442, in Series.__init__(self, data, index, dtype, name, copy, fastpath)
    440     index = default_index(len(data))
    441 elif is_list_like(data):
--> 442     com.require_length_match(data, index)
    444 # create/copy the manager
    445 if isinstance(data, (SingleBlockManager, SingleArrayManager)):
File ~\AppData\Local\Programs\Python\Python310\lib\site-packages\pandas\core\common.py:557, in require_length_match(data, index)
    553 """
    554 Check the length of data matches the length of the index.
    555 """
    556 if len(data) != len(index):
--> 557     raise ValueError(
    558         "Length of values "
    559         f"({len(data)}) "
    560         "does not match length of index "
    561         f"({len(index)})"
    562     )
ValueError: Length of values (1) does not match length of index (1024)

**

I am trying cifar10 puckle file to convert in images but failed ValueError: Length of values (1) does not match length of index (1024) how to fix it

I am trying cifar10 puckle file to convert in images but failed ValueError: Length of values (1) does not match length of index (1024) how to fix it

0 Answers
Related