I want to append a row in a python list.
Below is what I am trying,
# Create an empty array
arr=[]
values1 = [32, 748, 125, 458, 987, 361]
arr = np.append(arr, values1)
print arr
[ 32. 748. 125. 458. 987. 361.]
I want to append second row in the list, so that I will get an array like
[ [32. 748. 125. 458. 987. 361.], [42. 344. 145. 448. 187. 304.]]
I am getting error when I try to add second row
values2 = [42, 344, 145, 448, 187, 304]
arr = np.append(arr, values2)
How to do that?
Just append directly to your original list:
# Create an empty list
my_list = []
values1 = [32, 748, 125, 458, 987, 361]
my_list.append(values1)
print(my_list)
values2 = [42, 344, 145, 448, 187, 304]
my_list.append(values2)
print(my_list)
And this will be your output:
[[32, 748, 125, 458, 987, 361]]
[[32, 748, 125, 458, 987, 361], [42, 344, 145, 448, 187, 304]]
Hope that helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With