ilovecp3 - 5 months ago 14x

Python Question

new to Python, struggling in numpy, hope someone can help me, thank you!

`from numpy import *`

A = matrix('1.0 2.0; 3.0 4.0')

B = matrix('5.0 6.0')

C = matrix('1.0 2.0; 3.0 4.0; 5.0 6.0')

print "A=",A

print "B=",B

print "C=",C

results:

`A= [[ 1. 2.]`

[ 3. 4.]]

B= [[ 5. 6.]]

C= [[ 1. 2.]

[ 3. 4.]

[ 5. 6.]]

Question: how to use A and B to generate C, like in matlab C=[A;B]? Thank you so much

Answer

Use `numpy.concatenate`

:

```
>>> import numpy as np
>>> np.concatenate((A, B))
matrix([[ 1., 2.],
[ 3., 4.],
[ 5., 6.]])
```

Source (Stackoverflow)

Comments