What you can't do with hstack or vstack with dstack

a = np.array(['1', '2'])
b = np.array(['a', 'b'])

I want to combine a and b as follows

array([['1', 'a'],
       ['2', 'b']])

I couldn't do it with hstack or vstack, so I did it as follows.

>>>np.dstack((a, b))
array([[['1', 'a'],
        ['2', 'b']]])
>>>np.dstack((a, b)).shape
(1, 2, 2)
>>>c.reshape(c.shape[1], c.shape[2])
array([['1', 'a'],
       ['2', 'b']], dtype='<U1')

Recommended Posts

What you can't do with hstack or vstack with dstack
Python | What you can do with Python
What to do if you can't sort files with subscripts
[Python] What do you do with visualization of 4 or more variables?
What to do if you can't install pyaudio with pip #Python
What you can do with API vol.1
What to do if you can't build your project with Maven
What you can do with programming skills
What to do if you can't find well with grep's -f option
What to do if you can't find PDO in Laravel or CakePHP
What to do if you can't install with pip in babun environment
What to do if you can't pipenv shell
What to do if you can't pip install mysqlclient
What you can and cannot do with Tensorflow 2.x
What to do when you can't bind CaboCha to Python
What you can do with the Python standard library statistics
What to do if you can't log in as root
What to do if you can't use WiFi on Linux
What to do with Magics install
Consider what you can do with Python from the Qiita article
What to do if you get a UnicodeDecodeError with pip install
What to do with PYTHON release?
What to do if you can't use the trash in Lubuntu 18.04.
What to do when you get "I can't see the site !!!!"
What to do if you couldn't send an email to Yahoo with Python.
What to do if you can't use scikit grid search in Python
What to do if you get lost in file reference with FileNotFoundError
What to do if you get a TypeError with numpy min, max
What to do if you get Could not fetch URL 443 with pip
What do you roughly say "sudo su"?
Data analysis, what do you do after all?
Let's summarize what you want to do.
What to do if you get angry with swapon failed: Operation not permitted
You will be an engineer in 100 days --Day 35 --Python --What you can do with Python
What to do if you get an error when installing python with pyenv
Until you CI what you made with Django with Jenkins
What ICCV2019 Best paper SinGAN can't do [Practice]
What are you comparing with Python is and ==?
What should I do with DICOM in MPEG2?
What are you using when testing with Python?
What to do if you get an OpenSSL error when installing Python 2 with pyenv
How to install and use pyenv, what to do if you can't switch python versions
What to do if you get an Import Error when importing matplotlib with Jupyter
What to do if you can't hit the arrow keys in the Python interactive console
What to do if you run python in IntelliJ and end with an error