# Aggregate two points

**URL:** <https://openturns.discourse.group/t/aggregate-two-points/32>\
**Category:** Python usage\
**Tags:** api\
**Created:** [October 2, 2020, 10:56am UTC](https://openturns.discourse.group/t/aggregate-two-points/32 "2020-10-02T10:56:52Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![MichaelBaudin](https://yyz2.discourse-cdn.com/free1/user_avatar/openturns.discourse.group/michaelbaudin/32/9_2.png) [@MichaelBaudin](https://openturns.discourse.group/u/MichaelBaudin)\
**Post date:** [October 2, 2020, 10:56am UTC](https://openturns.discourse.group/t/aggregate-two-points/32/1 "2020-10-02T10:56:52Z")

</div>

Hi !  
I want to aggregate two Points `x` and `z`.

```auto
import openturns as ot
x = ot.Point([1.0, 2.0, 3.0])
y = ot.Point([4.0, 5.0])

```

I would like to produce the `Point([1.0, 2.0, 3.0, 4.0, 5.0])` by concatenating the values from `x` and `y`.

The first version that came to my mind was the “naive” way, using two `for` loops.

```auto
dimX = x.getDimension()
dimY = y.getDimension()
dim = dimX + dimY
z = ot.Point(dim)
for i in range(dimX):
    z[i] = x[i]
for i in range(dimY):
    z[i + dimX] = y[i]

```

Looking at the API more closely, I found the `add` method, which simplifies the scripts a bit:

```auto
z = ot.Point(x)
for i in range(dimY):
    z.add(y[i])

```

However, I have two regrets:

- we cannot add a full `Point` in one single statement with `z.add(y)` so that we cannot avoid a `for` loop here (without using Numpy),
- the verb `add` really means `append` (`add` may be confused with the vector addition).

Is there any other method that I missed in the API?  
Regards,  
Michaël

---

<div class="post-metadata">

**Author:** ![josephmure](https://yyz2.discourse-cdn.com/free1/user_avatar/openturns.discourse.group/josephmure/32/114_2.png) [@josephmure](https://openturns.discourse.group/u/josephmure)\
**Post date:** [October 2, 2020, 12:53pm UTC](https://openturns.discourse.group/t/aggregate-two-points/32/2 "2020-10-02T12:53:12Z")

</div>

I would do it this way:

```auto
import openturns as ot
x = ot.Point([1.0, 2.0, 3.0])
y = ot.Point([4.0, 5.0])

z = ot.Point(x)
z.add(y)
print(z)

```

Output:

```auto
[1,2,3,4,5]

```

---

<div class="post-metadata">

**Author:** ![MichaelBaudin](https://yyz2.discourse-cdn.com/free1/user_avatar/openturns.discourse.group/michaelbaudin/32/9_2.png) [@MichaelBaudin](https://openturns.discourse.group/u/MichaelBaudin)\
**Post date:** [October 5, 2020, 7:48am UTC](https://openturns.discourse.group/t/aggregate-two-points/32/3 "2020-10-05T07:48:39Z")

</div>

The example from the doc did not state that this is possible. Great, thank you!

Regards,

Michaël

---

<div class="post-metadata">

**Author:** ![josephmure](https://yyz2.discourse-cdn.com/free1/user_avatar/openturns.discourse.group/josephmure/32/114_2.png) [@josephmure](https://openturns.discourse.group/u/josephmure)\
**Post date:** [October 6, 2020, 9:39am UTC](https://openturns.discourse.group/t/aggregate-two-points/32/4 "2020-10-06T09:39:42Z")

</div>

Then I will update the doc when I have some time.

---

<div class="post-metadata">

**Author:** ![sofianehaddad](https://yyz2.discourse-cdn.com/free1/user_avatar/openturns.discourse.group/sofianehaddad/32/46_2.png) [@sofianehaddad](https://openturns.discourse.group/u/sofianehaddad)\
**Post date:** [October 19, 2020, 6:34pm UTC](https://openturns.discourse.group/t/aggregate-two-points/32/5 "2020-10-19T18:34:53Z")

</div>

Same idea for `Sample.add`. I do not know if it is already documented.  
Same concerning `Sample::stack`

---

<div class="post-metadata">

**Author:** ![KieranDelamotte](https://avatars.discourse-cdn.com/v4/letter/k/ce73a5/32.png) [@KieranDelamotte](https://openturns.discourse.group/u/KieranDelamotte)\
**Post date:** [November 6, 2020, 9:49am UTC](https://openturns.discourse.group/t/aggregate-two-points/32/6 "2020-11-06T09:49:09Z")

</div>

Concerning the `Sample.add` and `Sample.stack` methods, would not `Sample.vstack` and `Sample.hstack` better names ?

---

<div class="post-metadata">

**Author:** ![MichaelBaudin](https://yyz2.discourse-cdn.com/free1/user_avatar/openturns.discourse.group/michaelbaudin/32/9_2.png) [@MichaelBaudin](https://openturns.discourse.group/u/MichaelBaudin)\
**Post date:** [November 12, 2020, 9:04pm UTC](https://openturns.discourse.group/t/aggregate-two-points/32/7 "2020-11-12T21:04:34Z")

</div>

I agree with with you: `add` is a poor name choice. Horizontal and vertical names would be fine to me, but this refer to the `Sample` as an `np.array`, while the `Sample` has a dimension and a size. Would `addDimensions` and `addPoints` be clearer?
