Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A 3D NumPy array has three axes: its shape tells you how many positions lie along each one. For an array with shape (2, 3, 4), indexing with three integers selects one value, while a reduction such as sum(axis=0) collapses the first axis and leaves a result shaped (3, 4). The key is to track dimensions by their position in the shape tuple—not to assume an axis always means rows, columns, or depth.

What does a 3D NumPy shape mean?

NumPy’s shape is a tuple containing the length of each dimension, and ndim is the number of dimensions, or axes. The array’s size is the total number of elements. For example:

import numpy as np

x = np.arange(24).reshape(2, 3, 4)
print(x.shape)  # (2, 3, 4)
print(x.ndim)   # 3
print(x.size)   # 24

Read (2, 3, 4) positionally: axis 0 has length 2, axis 1 has length 3, and axis 2 has length 4. In this example, you can think of them as groups, rows, and columns: there are two groups, each with three rows of four values. That is a convenient description of this chosen arrangement, not a rule about what 3D arrays always represent. Another dataset might use the axes for time, latitude, and longitude, for example.

NumPy also stores a data type (dtype) for the elements. It is separate from shape: shape describes the array’s dimensions, not what its values represent.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • 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.

How do you index a 3D array?

Use one index for each axis to select one element. NumPy indexing is zero-based, like Python sequences, so the first position on an axis is index 0. For x, whose shape is (2, 3, 4):

x[1, 2, 3]  # scalar: group 1, row 2, column 3

Those indices refer to the second group, third row, and fourth column. Negative indices count backward from the end of an axis; for instance, x[-1, -1, -1] selects the final value in the array.

Integer indices remove an axis

An integer chooses one position and removes that axis from the result. Thus, x[1] selects one group and returns an array with shape (3, 4). The omitted trailing axes are treated as full slices, so it is equivalent to x[1, :, :].

Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 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.
x[1, :, :].shape  # (3, 4)
x[:, 1, :].shape  # (2, 4)

In the first expression, axis 0 is selected with an integer and disappears; axes 1 and 2 remain. In the second, axis 1 disappears instead, leaving axes 0 and 2.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Slices keep their axes

A slice selects a range of positions and retains its dimension, even if it selects only one position. For example:

x[:, :, 1:3].shape  # (2, 3, 2)
x[0:1].shape        # (1, 3, 4)

The slice 1:3 takes positions 1 and 2 on the last axis, so its length is 2. Compare x[0], which has shape (3, 4), with x[0:1], which has shape (1, 3, 4): the integer drops axis 0, while the slice preserves it with length 1.

Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • 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.

Basic slices usually create views rather than independent copies. Changing values through a view can change the original array, and a small view can keep the parent array’s allocation alive. If you need independent data, make a copy: part = x[0].copy().

What does the axis argument do in a reduction?

For a reduction such as sum, the axis identifies the dimension to collapse. Applied to shape (2, 3, 4), collapsing axis 0 combines the two positions along that axis and leaves axes 1 and 2. The output shape is therefore (3, 4).

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
x.sum(axis=0).shape  # (3, 4)
x.sum(axis=1).shape  # (2, 4)
x.sum(axis=2).shape  # (2, 3)
x.sum().shape        # scalar result

Use the shape tuple to predict each result: remove the entry for the axis being reduced and keep the others in their original order. With axis=None, the default for sum, all elements are aggregated into one scalar rather than a remaining array dimension. This rule is safer than calling axis=0 “rows” or “depth” without first establishing what those axes mean for the data.

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • 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
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

How are reshape, transpose, and other axis operations different?

These operations can all affect how dimensions appear, but they do different jobs. For x, the examples below show the resulting shapes:

Goal Operation Resulting shape What changes
Regroup the same elements x.reshape(6, 4) (6, 4) Changes grouping and index mapping; the total element count must remain 24.
Reorder all axes x.transpose(2, 0, 1) (4, 2, 3) Permutes the axes in the order specified.
Move a selected axis np.moveaxis(x, 0, -1) (3, 4, 2) Moves axis 0 to the final position.
Insert a length-one axis x[:, None, :, :] (2, 1, 3, 4) Adds a dimension, often to align shapes in a later expression.
Remove length-one axes np.squeeze(x[:, None, :, :]) (2, 3, 4) Drops axes of length 1; specify an axis when you want to remove only a particular one.

Reshape changes grouping, not axis order

reshape can change the shape only when the requested dimensions account for the same number of elements. It is useful for regrouping values, but it is not a substitute for swapping or moving axes. If your goal is to make an existing axis come first or last, use an axis-permutation operation instead.

Transpose and moveaxis reorder dimensions

transpose reorders axes according to the supplied permutation; x.transpose(2, 0, 1) makes the original axis 2 the first axis, axis 0 the second, and axis 1 the third. np.moveaxis is often clearer when only one selected axis needs to move. Transpose results can be views, so edits may affect the original array.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 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.

None, newaxis, and expand_dims add a dimension

Use None (also called np.newaxis) or np.expand_dims to insert an axis of length 1. A singleton axis can make dimensions line up for later operations, including broadcasting, but it does not add new values to the data.

Squeeze removes singleton dimensions

np.squeeze removes axes whose length is 1. If the array has more than one such axis, an unrestricted squeeze can remove each of them; pass an axis when you need precise control.

How can you check an unfamiliar result?

Print .shape after indexing, reducing, or rearranging an array. For each operation, ask which axes were selected, kept, collapsed, inserted, or reordered, then verify that the displayed shape matches that prediction. This small habit makes dimension changes visible instead of relying on ambiguous labels such as “rows.”

The examples here use basic integer indexing and slicing. NumPy’s advanced integer and boolean indexing have different shape and copy behavior, and broadcasting adds its own shape-compatibility rules; treat those as separate topics when you need them.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

References

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.