紹介された動画のコーディング作業画像を良く見ると、ほんの一瞬ですが該当部分のインデントを減らしてforループの外に移動させていました。
19:0020:26付近や21:52以後など

なので、以下の部分のインデントを解除してforループの外に移動すれば動作するでしょう。

    x_train = np.array(x_train) / 255.0
    y_train = np.array(y_train)
    x_test = np.array(x_test) / 255.0
    y_test = np.array(y_test)

単純にこちらのようにする。

x_train = np.array(x_train) / 255.0
y_train = np.array(y_train)
x_test = np.array(x_test) / 255.0
y_test = np.array(y_test)

以下は動画が紹介される前のソースコードだけで推測した内容です。
一応何か別の現象が起こった時などのための注意事項として残しておきます。


お手本の記事へのリンクとかソースコードの情報が追加されるかどうか分かりませんが、今のソースコードからすると、問題の原因は以下のコードによりPythonの基本的なリストとして定義された変数がnumpy.ndarrayに変換されてしまったことですね。
例えばこちらの記事と類似の現象です。
'numpy.ndarray' object has no attribute 'append'のエラーについて

リストとしての宣言と初期化

x_train = []
y_train = []
x_test = []
y_test = []

forループでの処理でndarrayに変換される

    x_train = np.array(x_train) / 255.0
    y_train = np.array(y_train)
    x_test = np.array(x_test) / 255.0
    y_test = np.array(y_test)

なので、forループの初回は以下の処理は正常に動作しますが、2回目以後はリストでは無くndarrayになっているのでエラーになります。

    if f.split("/")[6]=="train":
        x_train.append(img_data)
        y_train.append(int(f.split("/")[7].split("_")[0]))
    elif f.split("/")[6]=="test":
          x_test.append(img_data)
          y_test.append(int(f.split("/")[7].split("_")[0]))

最初からndarrayとして宣言・初期化しnp.appendを使うか、ループ後半のリスト全体をndarrayに変換してしまう処理を見直して必要なデータだけndarrayに変換するよう書き変えるか、のどちらかになると思われます。

Answer from kunif on Stack Overflow
Top answer
1 of 1
1

紹介された動画のコーディング作業画像を良く見ると、ほんの一瞬ですが該当部分のインデントを減らしてforループの外に移動させていました。
19:0020:26付近や21:52以後など

なので、以下の部分のインデントを解除してforループの外に移動すれば動作するでしょう。

    x_train = np.array(x_train) / 255.0
    y_train = np.array(y_train)
    x_test = np.array(x_test) / 255.0
    y_test = np.array(y_test)

単純にこちらのようにする。

x_train = np.array(x_train) / 255.0
y_train = np.array(y_train)
x_test = np.array(x_test) / 255.0
y_test = np.array(y_test)

以下は動画が紹介される前のソースコードだけで推測した内容です。
一応何か別の現象が起こった時などのための注意事項として残しておきます。


お手本の記事へのリンクとかソースコードの情報が追加されるかどうか分かりませんが、今のソースコードからすると、問題の原因は以下のコードによりPythonの基本的なリストとして定義された変数がnumpy.ndarrayに変換されてしまったことですね。
例えばこちらの記事と類似の現象です。
'numpy.ndarray' object has no attribute 'append'のエラーについて

リストとしての宣言と初期化

x_train = []
y_train = []
x_test = []
y_test = []

forループでの処理でndarrayに変換される

    x_train = np.array(x_train) / 255.0
    y_train = np.array(y_train)
    x_test = np.array(x_test) / 255.0
    y_test = np.array(y_test)

なので、forループの初回は以下の処理は正常に動作しますが、2回目以後はリストでは無くndarrayになっているのでエラーになります。

    if f.split("/")[6]=="train":
        x_train.append(img_data)
        y_train.append(int(f.split("/")[7].split("_")[0]))
    elif f.split("/")[6]=="test":
          x_test.append(img_data)
          y_test.append(int(f.split("/")[7].split("_")[0]))

最初からndarrayとして宣言・初期化しnp.appendを使うか、ループ後半のリスト全体をndarrayに変換してしまう処理を見直して必要なデータだけndarrayに変換するよう書き変えるか、のどちらかになると思われます。

Discussions

Week 2 Exercise 6 "'numpy.ndarray' object has no attribute 'append'"
Any idea why I am getting this error? Is costs not a numpy array? Exercise 5 runs properly but then I get this error after exercise 6 when using the line “costs.append(cost)”. Thanks for any help! More on community.deeplearning.ai
🌐 community.deeplearning.ai
4
0
March 8, 2022
paddleocr 3.3.1 PPStructureV3 推理 PDF 出现 'numpy.ndarray' object has no attribute 'append'
🔎 Search before asking I have searched the PaddleOCR Docs and found no similar bug report. I have searched the PaddleOCR Issues and found no similar bug report. I have searched the PaddleOCR Discus... More on github.com
🌐 github.com
2
November 7, 2025
scikit learn - AttributeError: 'numpy.ndarray' object has no attribute 'columns' - Data Science Stack Exchange
import numpy as np import pandas as pd from sklearn.ensemble import RandomForestClassifier from sklearn.model_selection import train_test_split from sklearn.feature_selection import SelectFromModel... More on datascience.stackexchange.com
🌐 datascience.stackexchange.com
June 21, 2019
AttributeError: 'numpy.ndarray' object has no attribute 'append'
Error is pretty clear: numpy arrays don't have an append method. There is a fake (and very expensive) numpy.append function you could use, but it would be a lot better to use a python list instead of a numpy array. X_new = [] More on reddit.com
🌐 r/learnpython
4
1
June 26, 2020
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-fix-numpy-ndarray-object-has-no-attribute-index
How to Fix: ‘numpy.ndarray’ object has no attribute ‘index’ - GeeksforGeeks
November 28, 2021 - ‘numpy.ndarray’ object has no attribute ‘index’ is an attribute error which indicates that there is no index method or attribute available to use in Numpy array.
🌐
Career Karma
careerkarma.com › blog › python › python attributeerror: ‘numpy.ndarray’ object has no attribute ‘append’ solution
Python AttributeError: 'numpy.ndarray' object has no attribute 'append' Solution
December 1, 2023 - The AttributeError: ‘numpy.ndarray’ object has no attribute ‘append’ error is caused by using the append() method to add an item to a NumPy array.
🌐
DeepLearning.AI
community.deeplearning.ai › course q&a › deep learning specialization › neural networks and deep learning
Week 2 Exercise 6 "'numpy.ndarray' object has no attribute 'append'" - Neural Networks and Deep Learning - DeepLearning.AI
March 8, 2022 - Any idea why I am getting this error? Is costs not a numpy array? Exercise 5 runs properly but then I get this error after exercise 6 when using the line “costs.append(cost)”. Thanks for any help!
Find elsewhere
🌐
Statology
statology.org › home › how to fix: ‘numpy.ndarray’ object has no attribute ‘append’
How to Fix: 'numpy.ndarray' object has no attribute 'append'
August 4, 2021 - AttributeError: 'numpy.ndarray' object has no attribute 'append' This error occurs when you attempt to append one or more values to the end of a NumPy array by using the append() function in regular Python.
🌐
GitHub
github.com › PaddlePaddle › PaddleOCR › issues › 17004
paddleocr 3.3.1 PPStructureV3 推理 PDF 出现 'numpy.ndarray' object has no attribute 'append' · Issue #17004 · PaddlePaddle/PaddleOCR
November 7, 2025 - paddleocr 3.3.1 PPStructureV3 推理 PDF 出现 'numpy.ndarray' object has no attribute 'append'#17004
Author   axmmisaka
🌐
TechGeekBuzz
techgeekbuzz.com › blog › python-attributeerror-numpy-ndarray-object-has-no-attribute-append-solution
Python AttributeError: 'numpy.ndarray' object has no attribute 'append' Solution
The append() is the numpy's method, ... you are getting this error in your Python program this means you are trying to call the append() method on your array object....
🌐
Itsourcecode
itsourcecode.com › home › (solved) numpy.ndarray object has no attribute append
(SOLVED) numpy.ndarray object has no attribute append
March 21, 2023 - To solve or fix this error ‘numpy.ndarray’ object has no attribute ‘append’, you just need to use the other method for adding elements to the array numpy. The following are the alternatives to append the method: ... import numpy as np ...
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-fix-numpy-ndarray-object-has-no-attribute-append
How to Fix: ‘numpy.ndarray’ object has no attribute ‘append’ - GeeksforGeeks
November 28, 2021 - The output is pretty explanatory, the NumPy array has a type of numpy.ndarray which does not have any append() method. Now, we know that the append is not supported by NumPy arrays then how do we use it? It is actually a method of NumPy and not its array, let us understand it through the example given below, where we actually perform the append operation on a numpy list. ... values: numpy array or value: These values are appended to a copy of arr.
🌐
Itsourcecode
itsourcecode.com › home › attributeerror: numpy.ndarray object has no attribute values
Attributeerror: numpy.ndarray object has no attribute values
April 4, 2023 - This attributeerror: numpy.ndarray object has no attribute values error occurs when you try to access the “values” attribute of a NumPy ndarray object, but it does not exist.
🌐
Built In
builtin.com › articles › attributeerror-dataframe-object-has-no-attribute-append
AttributeError: ‘DataFrame’ Object Has No Attribute ‘Append’ Solved | Built In
July 8, 2024 - AttributeError: ‘DataFrame’ object has no attribute ‘append’ can be solved by replacing append() with the concat() method to merge two or more Pandas DataFrames together.
🌐
DataScientYst
datascientyst.com › fix-attributeerror-dataframe-object-has-no-attribute-append-pandas
AttributeError: 'DataFrame' object has no attribute 'append' - Pandas
January 19, 2024 - To sum up, this article shows how using method concat can solve the "AttributeError: 'DataFrame' object has no attribute 'append'" Python error.
🌐
Arab Psychology
scales.arabpsychology.com › home › how to easily fix the “numpy.ndarray” append error
How To Easily Fix The "numpy.ndarray" Append Error
December 4, 2025 - The common error, AttributeError: ‘numpy.ndarray’ object has no attribute ‘append’, arises from a fundamental misunderstanding of the object types in Python. A numpy.ndarray is specifically designed for high-performance numerical operations ...
🌐
Quora
quora.com › Why-do-I-get-numpy-ndarray-object-has-no-attribute-append-error
Why do I get “numpy.ndarray object has no attribute append error”? - Quora
This error occurs because numpy.ndarray objects do not implement the list method append — numpy arrays have a fixed size and their API differs from Python lists. Calling arr.append(...) raises AttributeError.