Numpy ndarrays are meant for all elements to have the same length. In this case, your second array doesn’t contain lists of the same length, so it ends up being a 1-D array of lists, as opposed to a “proper” 2-D array.
From the Numpy docs on N-dimensional arrays:
An ndarray is a (usually fixed-size) multidimensional container of items of the same type and size.
a = np.array([[1,2,3,4], [5,6,7,8], [9,10,11,12]]) a.shape # (3,4) a.ndim # 2 b = np.array([[1,2,3,4], [5,6,7,8], [9,10,11]]) b.shape # (3,) b.ndim # 1
This discussion may be useful.
Related Posts:
- Python3 – ModuleNotFoundError: No module named ‘numpy’
- ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
- Curve curvature in numpy
- How can I prevent the TypeError: list indices must be integers, not tuple when copying a python list to a numpy array?
- Converting NumPy array into Python List structure?
- The difference between comparison to np.nan and isnull()
- ‘numpy.ndarray’ object has no attribute ‘index’
- TypeError: only integer scalar arrays can be converted to a scalar index with 1D numpy indices array
- Is there a way to create multiline comments in Python?
- How to update/upgrade a package using pip?
- How can I remove a specific item from an array?
- How do I update\upgrade pip itself from inside my virtual environment?
- IndexError: too many indices for array
- Import Error: No module named numpy
- What is the purpose of the return statement?
- How to read a large file – line by line?
- deleting file if it exists; python
- Why am I seeing “TypeError: string indices must be integers”?
- Python Linked List
- What is the result of % in Python?
- How to print without a newline or space
- Python time.sleep() vs event.wait()
- Program to Unjumble Words on Python [closed]
- Error: ‘int’ object is not subscriptable – Python
- How to overcome TypeError: unhashable type: ‘list’
- Does Python have a ternary conditional operator?
- How do I install opencv using pip?
- How do I compare two strings in python?
- What are data classes and how are they different from common classes?
- Tensorflow import error: No module named ‘tensorflow’
- Python random function
- Python Dictionary Comprehension
- How do you get the logical xor of two variables in Python?
- ValueError: could not convert string to float: id
- Converting string into datetime
- Pip freeze vs. pip list
- Best way to return multiple values from a function? [closed]
- Difference between import numpy and import numpy as np
- Numpy ValueError: setting an array element with a sequence. This message may appear without the existing of a sequence?
- numpy division with RuntimeWarning: invalid value encountered in double_scalars
- Converting list to numpy array
- How do you do natural logs (e.g. “ln()”) with numpy in Python?
- How do I read CSV data into a record array in NumPy?
- How to normalize a NumPy array to a unit vector?
- Factorial in numpy and scipy
- How to count the occurrence of certain item in an ndarray?
- size of NumPy array
- Singular matrix issue with Numpy
- Python Pandas – Missing required dependencies [‘numpy’] 1
- Syntax in Python (.T)
- Convert a tensor to numpy array in Tensorflow?
- Using Numpy Vectorize on Functions that Return Vectors
- Use a.any() or a.all()
- A tool to convert MATLAB code to Python
- Most efficient way to map function over numpy array
- initialize a numpy array
- Cannot convert list to array: ValueError: only one element tensors can be converted to Python scalars
- How can I use numpy.correlate to do autocorrelation?
- Calculating Covariance with Python and Numpy
- How to access the ith column of a NumPy multidimensional array?
- Dump a NumPy array into a csv file
- Python: find position of element in array
- Inverse of a matrix using numpy
- How to convert a PIL Image into a numpy array?
- numpy with python: convert 3d array to 2d
- Python: slicing a multi-dimensional array
- How to implement the Softmax function in Python
- Add single element to array in numpy
- How do you get the magnitude of a vector in Numpy?
- How to calculate rolling / moving average using python + NumPy / SciPy?
- ValueError: object too deep for desired array while using convolution
- Make list of arrays in python
- Import Error: No module named numpy Anaconda
- Dictionary in a numpy array?
- pandas create new column based on values from other columns / apply a function of multiple columns, row-wise
- How to fix “TypeError: len() of unsized object”
- How to calculate a Gaussian kernel matrix efficiently in numpy?
- How to get the unit vector from a numpy array
- “Divide by zero encountered in log” when not dividing by zero
- Good ways to “expand” a numpy ndarray?
- TypeError: ‘numpy.float64’ object does not support item assignment
- Python/Django: log to console under runserver, log to file under Apache
- TensorFlow not found using pip
- Efficiently sorting a numpy array in descending order?
- How to create a numpy array of lists?
- How to fix ‘RuntimeWarning: divide by zero encountered in double_scalars’
- Python can’t multiply sequence by non-int of type ‘float’
- IndexError: index 2 is out of bounds for axis 0 with size 2
- Create numpy matrix filled with NaNs
- built-in range or numpy.arange: which is more efficient?
- How to print the full NumPy array, without truncation?
- Calculate weighted average using a pandas/dataframe
- How to install NumPy for Python 3.6
- Complex number troubles with numpy
- Filtering a NumPy Array
- TypeError: zip argument #2 must support iteration
- CS231n: How to calculate gradient for Softmax loss function?
- How to zip two 1d numpy array to 2d numpy array [duplicate]
- Numpy matrix to array
- numpy/scipy/ipython:Failed to interpret file as a pickle