It’s working exactly as it’s supposed to. The transpose of a 1D array is still a 1D array! (If you’re used to matlab, it fundamentally doesn’t have a concept of a 1D array. Matlab’s “1D” arrays are 2D.)
If you want to turn your 1D vector into a 2D array and then transpose it, just slice it with np.newaxis
(or None
, they’re the same, newaxis
is just more readable).
import numpy as np a = np.array([5,4])[np.newaxis] print(a) print(a.T)
Generally speaking though, you don’t ever need to worry about this. Adding the extra dimension is usually not what you want, if you’re just doing it out of habit. Numpy will automatically broadcast a 1D array when doing various calculations. There’s usually no need to distinguish between a row vector and a column vector (neither of which are vectors. They’re both 2D!) when you just want a vector.
Related Posts:
- TypeError: only integer scalar arrays can be converted to a scalar index with 1D numpy indices array
- Import Error: No module named numpy
- ValueError: setting an array element with a sequence
- Difference between import numpy and import numpy as np
- Numpy ValueError: setting an array element with a sequence. This message may appear without the existing of a sequence?
- numpy: Invalid value encountered in true_divide
- python numpy ValueError: operands could not be broadcast together with shapes
- How to fix IndexError: invalid index to scalar variable
- Could not install packages due to a “Environment error :[error 13]: permission denied : ‘usr/local/bin/f2py'”
- numpy division with RuntimeWarning: invalid value encountered in double_scalars
- How does numpy.newaxis work and when to use it?
- Converting list to numpy array
- How do you do natural logs (e.g. “ln()”) with numpy in Python?
- How do I read CSV data into a record array in NumPy?
- How to normalize a NumPy array to a unit vector?
- Factorial in numpy and scipy
- Convert pandas dataframe to NumPy array
- Unable to plot Double Bar, Bar plot using pyplot for ndarray
- How to count the occurrence of certain item in an ndarray?
- size of NumPy array
- Singular matrix issue with Numpy
- Python Pandas – Missing required dependencies [‘numpy’] 1
- ‘DataFrame’ object has no attribute ‘sort’
- Convert a tensor to numpy array in Tensorflow?
- ValueError: all the input arrays must have same number of dimensions
- TypeError: cannot unpack non-iterable int objec
- ValueError: setting an array element with a sequence
- Using Numpy Vectorize on Functions that Return Vectors
- Use a.any() or a.all()
- ‘End of statement expected’ in pycharm
- Most efficient way to map function over numpy array
- initialize a numpy array
- Cannot convert list to array: ValueError: only one element tensors can be converted to Python scalars
- How can I use numpy.correlate to do autocorrelation?
- Calculating Covariance with Python and Numpy
- How to access the ith column of a NumPy multidimensional array?
- Dump a NumPy array into a csv file
- Python: find position of element in array
- Inverse of a matrix using numpy
- How to convert a PIL Image into a numpy array?
- Overcome ValueError for empty array
- numpy with python: convert 3d array to 2d
- Python: slicing a multi-dimensional array
- Pytorch reshape tensor dimension
- How to remove specific elements in a numpy array
- Add single element to array in numpy
- Overflow / math range error for log or exp
- Creating a Pandas DataFrame from a Numpy array: How do I specify the index column and column headers?
- Overflow Error in Python’s numpy.exp function
- How do you get the magnitude of a vector in Numpy?
- How to calculate rolling / moving average using python + NumPy / SciPy?
- ValueError: object too deep for desired array while using convolution
- Make list of arrays in python
- Import Error: No module named numpy Anaconda
- Dictionary in a numpy array?
- Understanding NumPy’s einsum
- RuntimeWarning: divide by zero encountered in log
- pandas create new column based on values from other columns / apply a function of multiple columns, row-wise
- Error NameError: name ‘np’ is not defined
- How to fix “TypeError: len() of unsized object”
- Numpy.dot TypeError: Cannot cast array data from dtype(‘float64’) to dtype(‘S32’) according to the rule ‘safe’
- NumPy array is not JSON serializable
- How to calculate a Gaussian kernel matrix efficiently in numpy?
- How to get the unit vector from a numpy array
- Does Numpy automatically detect and use GPU?
- How can I check whether a numpy array is empty or not?
- “Divide by zero encountered in log” when not dividing by zero
- Good ways to “expand” a numpy ndarray?
- TypeError: ‘numpy.float64’ object does not support item assignment
- Official abbreviation for: import scipy as sp/sc
- Efficiently sorting a numpy array in descending order?
- How to plot an array in python?
- How to create a numpy array of all True or all False?
- How to create a numpy array of lists?
- Removing nan values from an array
- How to fix ‘RuntimeWarning: divide by zero encountered in double_scalars’
- Building multi-regression model throws error: `Pandas data cast to numpy dtype of object. Check input data with np.asarray(data).`
- IndexError: index 2 is out of bounds for axis 0 with size 2
- Create numpy matrix filled with NaNs
- built-in range or numpy.arange: which is more efficient?
- Concat DataFrame Reindexing only valid with uniquely valued Index objects
- Replacing Pandas or Numpy Nan with a None to use with MysqlDB
- threshold in 2D numpy array
- Numpy Resize/Rescale Image
- numpy array concatenation error: 0-d arrays can’t be concatenated
- How to print the full NumPy array, without truncation?
- Calculate weighted average using a pandas/dataframe
- RuntimeError: module compiled against API version 0xc but this version of numpy is 0xb
- How to install NumPy for Python 3.6
- Complex number troubles with numpy
- numpy : calculate the derivative of the softmax function
- Filtering a NumPy Array
- How to install numpy to Python 3.5?
- Conditional indexing with Numpy ndarray
- python numpy machine epsilon
- Function to determine if two numbers are nearly equal when rounded to n significant decimal digits
- TypeError: zip argument #2 must support iteration
- CS231n: How to calculate gradient for Softmax loss function?
- How to zip two 1d numpy array to 2d numpy array [duplicate]
- numpy/scipy/ipython:Failed to interpret file as a pickle