For a two-dimensional NumPy array, use a.T to swap rows and columns. NumPy also provides a.transpose(), np.transpose(), and targeted axis operations; for a plain nested list, use zip(*matrix). The right choice depends on the data type and, for multidimensional arrays, which axes you want to rearrange.
Transpose a 2D NumPy array
Here is a non-square array so the row-and-column change is easy to see:
import numpy as np
a = np.array([[1, 2, 3],
[4, 5, 6]])
Its shape is (2, 3): two rows and three columns. A transpose exchanges those dimensions and produces:
[[1, 4],
[2, 5],
[3, 6]]
1. Use the .T property
a_t = a.T
For a two-dimensional NumPy array, .T is the concise way to exchange rows and columns. NumPy documents it as equivalent to the ndarray transpose method: ndarray.T.
#1 Best Overall
- Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
- Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
- Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
- Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
- 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
2. Call .transpose()
a_t = a.transpose()
With no axes specified, this method reverses the order of all axes. It can be useful when a method call fits the style of a transformation pipeline. NumPy returns a view when possible; see ndarray.transpose.
3. Call np.transpose()
a_t = np.transpose(a)
The function form gives the same 2D result and lets you specify the output axis order for higher-dimensional arrays. For a three-dimensional input, np.transpose(a, (1, 0, 2)) swaps the first two axes and leaves the third in place. The axes must form a permutation of the input axes; negative axis indices are also accepted. See numpy.transpose.
Rank #2
- 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
- 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
- Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
- 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
- What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
Change selected axes in a multidimensional array
For more than two dimensions, decide whether you intend to exchange a pair of axes, move axes to new positions, or reverse the full axis order. A default transpose reverses every axis; it is not always the same as swapping just the last two dimensions.
4. Use swapaxes or moveaxis
b = np.swapaxes(a, 0, 1)
c = np.moveaxis(a, 0, 1)
On a 2D input, both examples produce the familiar row-and-column exchange. For higher-dimensional inputs, swapaxes exchanges the two named axes. moveaxis moves the selected source axis to the destination position while keeping the other axes in their relative order. Pick the function that describes the change you mean; neither is a general synonym for reversing all axes. See numpy.moveaxis.
Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchWindows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallRank #3
- Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
- Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
- Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
- Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
- What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
Transpose a plain nested list without NumPy
5. Use zip(*matrix)
matrix = [[1, 2, 3],
[4, 5, 6]]
transposed = list(zip(*matrix))
# [(1, 4), (2, 5), (3, 6)]
Unpacking the rows as arguments to zip groups their first elements, then their second elements, and so on. The result contains tuples. To get a list of lists instead, convert each tuple:
transposed = [list(row) for row in zip(*matrix)]
# [[1, 4], [2, 5], [3, 6]]
The Python documentation describes zip() as turning rows into columns and columns into rows: Python built-in functions. By default, zip stops at the shortest row, so a ragged nested list can lose trailing values. In Python 3.10 and later, zip(*matrix, strict=True) raises ValueError when the rows have different lengths. The Python tutorial also shows the transpose idiom: Nested list comprehensions.
Rank #4
- Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
- Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
- Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
- Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
- Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
Handle 1D and n-dimensional NumPy arrays correctly
A 1D array stays one-dimensional
Transposing a one-dimensional array does not turn it into a row or column vector: np.transpose(a) returns an unchanged view. To make a column vector, add an axis explicitly:
column = np.atleast_2d(a).T
# or
column = a[:, np.newaxis]
NumPy documents this behavior in numpy.transpose.
Default transpose reverses all axes
For an array with shape (2, 3, 4), a default transpose produces shape (4, 3, 2). Supply an axis permutation when you need a different arrangement, such as swapping only the first two axes. Do not infer the intended result from the word “transpose” alone; specify the axes that should move.
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Scan for outdated or missing drivers - takes under a minute3Clear out junk files and repair common Windows errorsBest Value
- 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
- Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
- Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
- HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
- What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
A transpose may share storage with its input
NumPy returns a view whenever possible, so modifying a transposed array may affect the original array. If you need independent storage, make an explicit copy, for example a.T.copy(). The applicable behavior is described in numpy.transpose and ndarray.transpose.
Transpose a pandas DataFrame
For a DataFrame, use df.T or df.transpose() to exchange its index and columns. If the DataFrame contains mixed data types, the transposed frame has a homogeneous object dtype. In pandas 3.0, the method’s copy argument is ignored and deprecated; the method uses lazy Copy-on-Write behavior, and a copy is always required for mixed-dtype DataFrames or extension types. Consult the current DataFrame.transpose documentation for details.
Quick Recap
Choose the method that matches your data
| Data or goal | Recommended form | What to keep in mind |
|---|---|---|
| 2D NumPy array | a.T |
Concise row-and-column exchange. |
| NumPy array with explicit axis order | np.transpose(a, axes=...) |
Controls the position of every output axis. |
| Exchange two selected NumPy axes | np.swapaxes(a, axis1, axis2) |
Only the named pair is exchanged. |
| Move selected NumPy axes | np.moveaxis(a, source, destination) |
Other axes keep their relative order. |
| pandas DataFrame | df.T or df.transpose() |
Mixed dtypes produce an object-dtype transposed frame. |
| Rectangular nested list | list(zip(*matrix)) |
Elements are tuples; unequal rows truncate by default. Use strict=True in Python 3.10 or later to detect unequal lengths. |
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

