-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])
2
  • You generally don't. If you want something variable-sized, use a list Commented Feb 4, 2021 at 20:47
  • With numpy add means the mathematic operation. Arrays can be added to arrays or scalars. Commented Feb 4, 2021 at 21:02

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

0

Try this approach:

np.insert(yourarrayname, 2, [10, 20, 30], axis=0)

1 Comment

When adding at the end (or beginning) vstack is faster. insert is a more general purpose function, and slower.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.