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?

2

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.