2

I've got some data which I've arranged in the form of [[[0, 1], [2, 3]], [[4, 5], [6,7]]], e.g. 3 dimensions. However, the function I'm using requires a numpy array to work, so I need to convert it from nested lists into one. Whenever I try though I always find that the fist two layers of lists convert, but the final one doesn't? e.g. If I try to print:

print(data)          # Prints a numpy.ndarray
print(data[0][0])    # Prints a numpy.ndarray
print(data[0][0][0]) # Prints a list

I've tried a few different methods to convert it, but they all return the data like this? Anyone got any ideas what I can do?

Seanny123
  • 8,776
  • 13
  • 68
  • 124
Tom Warner
  • 21
  • 1
  • 2

1 Answers1

2

A bit confused on what your data refers to, but given

import numpy as np

x = [[[0, 1], [2, 3]], [[4, 5], [6,7]]]

# convert to numpy.ndarray
y = np.asarray(x)
print(type(y)) # y is now a numpy.ndarray

# Checking dimensions
print(y.shape)  # (2,2,2) - 3D array
Ryjhan
  • 21
  • 2