Issue
Good morning,
I am trying to add elements from one numpy array to the other.
Jack = ["red", "blue", "yellow"]
Louise = ["orange", "green", "purple"]
When I do the following line, it adds the entire array instead of the elements.
Jack.append(Louise)
Out:
[["red", "blue", "yellow"],["orange", "green", "purple"]]
What I want to obtain in the end is:
["red", "blue", "yellow", "orange", "green", "purple]
Solution
If you want to do it in numpy
you can use numy.concatenate
with axis=0
and if you want in list
you can use list_1 + list_2
.
Jack = np.array(["red", "blue", "yellow"])
Louise = np.array(["orange", "green", "purple"] )
out = np.concatenate((Jack, Louise), axis=0)
print(out)
# ['red' 'blue' 'yellow' 'orange' 'green' 'purple']
>>> Jack = ["red", "blue", "yellow"]
>>> Louise = ["orange", "green", "purple"]
>>> Jack + Louise
['red', 'blue', 'yellow', 'orange', 'green', 'purple']
Answered By - I'mahdi
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.