mercredi 28 avril 2021

Join 2 randomly genreted list

I am trying to join 2 randomly generated list into one but its adding them element wise. Suppose I generated 2 list each with 2 random numbers I want my output list to be of numbers. For example:

import numpy as np

x1 = np.random.uniform(0,0.1, 2)
x2 = np.random.uniform(0,0.1, 2)

x = x1 + x2

print(x1)
print(x2)
print(x)
The output is: 
[0.06878713 0.03807816]
[0.01801809 0.06292975]
[0.08680523 0.10100791]

But I want my output as 
[0.06878713 0.03807816]
[0.01801809 0.06292975]
[0.06878713 0.03807816 0.01801809 0.06292975]

If I use append() or extend() its giving me: AttributeError: 'numpy.ndarray' object has no attribute 'append'.




Aucun commentaire:

Enregistrer un commentaire