-1

Lets say I have two arrays. the first one prints out in the terminal as follows:

[[1.11926603 0.66536009 0.63453309]
 [0.57149771 0.43967367 0.30005988]]

So basically this array has two groups.

Now I would like to add another group to this array. I have tried using add and append without any luck.

What I want is something that looks as follows:

[[1.11926603 0.66536009 0.63453309]
 [0.57149771 0.43967367 0.30005988]
 [x.xxxxx y.yyyyy z.zzzzz]] 

And so forth.

This is the code I have so far:

#This part creates the first array with two groups. It is from the Open3D library
pcl = o3d.geometry.PointCloud()
pcl.points = o3d.utility.Vector3dVector(np.random.randn(2, 3))

#This part prints out the result to see if it worked
#print(np.add(pcl.points, [10, 20, 30])) - not working
#print(np.append(pcl.points, [10, 20, 30])) - not working

Essentially I would like to add more points to the current point cloud. Something like this:

pcl.points = np.add(pcl.points, [10,20,30])
Paul Brink
  • 332
  • 1
  • 4
  • 21

2 Answers2

1

What about numpy.vstack?

A = np.array([[1.11926603, 0.66536009, 0.63453309],
    [0.57149771, 0.43967367, 0.30005988]])
B = np.array([x.xxxxx, y.yyyyy, z.zzzzz])
A = np.vstack((A, B))

...gives the wanted result.

4ndY
  • 88
  • 7
0

Try this approach:

np.insert(yourarrayname, 2, [10, 20, 30], axis=0)
Jaime Etxebarria
  • 560
  • 3
  • 14
Bartnatz
  • 13
  • 6
  • When adding at the end (or beginning) `vstack` is faster. `insert` is a more general purpose function, and slower. – hpaulj Feb 04 '21 at 21:15