0

This is my code:

image_array.append(image)
label_array.append(i)
    
image_array = np.array(image_array)
label_array = np.array(label_array, dtype="float")

This is the error:

AttributeError: 'numpy.ndarray' object has no attribute 'append'
Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
RVC
  • 19
  • 1
  • 1
    Does this answer your question? [AttributeError: 'numpy.ndarray' object has no attribute 'append'](https://stackoverflow.com/questions/8409498/attributeerror-numpy-ndarray-object-has-no-attribute-append) – Tomerikoo Nov 15 '22 at 09:52

2 Answers2

2

numpy.append expects two input atleast. see this example

import numpy as np

#define NumPy array
x = np.array([1, 4, 4, 6, 7, 12, 13, 16, 19, 22, 23])

#append the value '25' to end of NumPy array
x = np.append(x, 25)

#view updated array
x

array([ 1,  4,  4,  6,  7, 12, 13, 16, 19, 22, 23, 25])
M Imran
  • 109
  • 7
1

From what I can recall, you are writing the append in the wrong way (check here the example in the doc https://numpy.org/doc/stable/reference/generated/numpy.append.html)

image_array = np.append(image_array, [image])
label_array = np.append(label_array, [i])

Arrays must have the same dimensions

Marco Massetti
  • 539
  • 4
  • 12