It’s easier like this:
k.reshape(k.shape + (1,))
But if all you want is to add an empty dimension at the end, you should use numpy.newaxis
:
import numpy as np
k = k[..., np.newaxis]
or
k = k[..., None]
(See the documentation on slicing).
More Related Contents:
- Intuition and idea behind reshaping 4D array to 2D array in NumPy
- Reshape an array in NumPy
- load csv into 2D matrix with numpy for plotting
- How to print the full NumPy array, without truncation?
- Convert Python sequence to NumPy array, filling missing values
- Numpy array assignment with copy
- numpy matrix vector multiplication [duplicate]
- Repeating each element of a numpy array 5 times
- how does multiplication differ for NumPy Matrix vs Array classes?
- Conditionally fill column values based on another columns value in pandas
- Ambiguity in Pandas Dataframe / Numpy Array “axis” definition
- How to create a numpy array of arbitrary length strings?
- Numpy modify array in place?
- Subsetting a 2D numpy array
- How to normalize a 2-dimensional numpy array in python less verbose?
- What is the difference between ndarray and array in NumPy?
- Removing elements from an array that are in another array
- Stocking large numbers into numpy array
- check for identical rows in different numpy arrays
- pd.Timestamp versus np.datetime64: are they interchangeable for selected uses?
- Numpy: For every element in one array, find the index in another array
- Prevent numpy from creating a multidimensional array
- Inverting a numpy boolean array using ~
- Cannot understand numpy argpartition output
- Using numpy ‘module’ object has no attribute ‘array’ [duplicate]
- Python: Split NumPy array based on values in the array
- Python, OpenCV: Increasing image brightness without overflowing UINT8 array
- Append 2D array to 3D array, extending third dimension
- Working with floating point NumPy arrays for comparison and related operations
- Mapping a NumPy array in place