Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
I want to add something to a ndarray, what am I doing wrong?
import numpy as np sequence =np.repeat(1, 4) print(sequence) np.append(sequence, 7) print(sequence)
Expected result in console: [1 1 1 1] [1 1 1 1 7]
Actual result: [1 1 1 1] [1 1 1 1]
sequence = np.append(sequence, 7)
np.append
np.append() returns a new list, so what you wanna do is you wanna do sequence = np.append(sequence, 7)
np.append()
Add a comment
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.
sequence = np.append(sequence, 7)np.appendnp.appendis not a list append clone. Do not use as such; better yet don't use it at all! Also you can't add an element to just one row of a 2d array. Again, arrays are not the same as nested lists.