pythonnumpyscipytranspose# Numpy transpose of 1D array not giving expected result

I am trying a very basic example in Python scipy module for `transpose()`

method but it's not giving expected result. I am using Ipython with pylab mode.

```
a = array([1,2,3]
print a.shape
>> (3,)
b = a.transpose()
print b.shape
>> (3,)
```

If I print the contents of arrays "a" and "b", they are similar.

Expectation is: (which will be result in Matlab on transpose)

```
[1,
2,
3]
```

Solution

NumPy's `transpose()`

effectively reverses the shape of an array. If the array is one-dimensional, this means it has no effect.

In NumPy, the arrays

```
array([1, 2, 3])
```

and

```
array([1,
2,
3])
```

are actually the same – they only differ in whitespace. What you probably want are the corresponding two-dimensional arrays, for which `transpose()`

would work fine. Also consider using NumPy's `matrix`

type:

```
In [1]: numpy.matrix([1, 2, 3])
Out[1]: matrix([[1, 2, 3]])
In [2]: numpy.matrix([1, 2, 3]).T
Out[2]:
matrix([[1],
[2],
[3]])
```

Note that for most applications, the plain one-dimensional array would work fine as both a row or column vector, but when coming from Matlab, you might prefer using `numpy.matrix`

.

- Python Jinja2 LaTeX Table
- Getting attributes of a class
- How can I print many significant figures in Python?
- How to allow list append() method to return the new list
- Calculate Last Friday of Month in Pandas
- Python type hint for Iterable[str] that isn't str
- How to iterate over a list in chunks
- How to exit the entire application from a Python thread?
- Running shell command and capturing the output
- How do I pass a variable by reference?
- Convert range(r) to list of strings of length 2 in python
- How can I get the start and end dates for each week?
- how to use send_message() in python-telegram-bot
- Python conditional replacement based on element type
- How can I count the number of items in an arbitrary iterable (such as a generator)?
- Find longest consecutive range of numbers in list
- Insert text in braces with asyncpg
- How does one put a link / url to the web-site's home page in Django?
- How to determine if a path is a subdirectory of another?
- Custom Keybindings for Ipython terminal
- FastAPI asynchronous background tasks blocks other requests?
- How to make sure that information from one file is duplicated into several text documents, without specific lines
- Installing a Python environment with Anaconda
- sklearn pipeline model predicting same results for all input
- Brew command not found after installing Anaconda Python
- How to get an XPath from selenium webelement or from lxml?
- Pipe PuTTY console to Python script
- How to align the axes of a figure in matplotlib?
- Persist ParentDocumentRetriever of langchain
- How to reset index in a pandas dataframe?