Appending value

Question:

I know this question may have already been asked, but I’m not finding it, what I’d like to know is how I can use numpy to insert values ​​just like I use append for lists (determining a position) without losing formatting (dimensions), and if possible I would like to know how to insert a value in any position in the list

import numpy as np

a = np.array([[1, 2, 3],[4, 5, 6]])

y = [[x for x in range(1, 4)],[x for x in range(4, 7)]]

print("________APPEND FOR LIST__________")
y[1].append(100)
print(y)
print("________APPEND FOR NUMPY?__________")
return_a = np.append(a[1], 100) 
print(return_a) # EXIT [  4   5   6 100] desired output [[1, 2, 3], [4, 5, 6, 100]]

print("________INSERT FOR LIST__________")
y[0][2] = 200
print(y)
print("________INSERT FOR NUMPY?__________")
return_a = ? # desired output with numpy [[1, 2, 3, 200], [4, 5, 6, 100]]
print(return_a)

I put how the operations work in the lists so you can understand how I would like it to work for numpy

Asked By: Rafael MR

||

Answers:

There is no simple function or solution that fulfills what was asked

Answered By: Rafael MR
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.