If you have a list of lists, you only needed to use ...

import numpy as np
...
npa = np.asarray(someListOfLists, dtype=np.float32)

per this LINK in the scipy / numpy documentation. You just needed to define dtype inside the call to asarray.

Answer from Thom Ives on Stack Overflow
๐ŸŒ
NumPy
numpy.org โ€บ doc โ€บ stable โ€บ user โ€บ basics.creation.html
Array creation โ€” NumPy v2.5 Manual
numpy.ones, numpy.zeros, and random define arrays based upon the desired shape. The ndarray creation functions can create arrays with any dimension by specifying how many dimensions and length along that dimension in a tuple or list.
Discussions

python - How to create a numpy array of lists? - Stack Overflow
Lists aren't very numpy anyway, so maybe a tuple of lists is good enough for you. You can get that easily and rather efficiently with an iterator expression: ... You can leave out the tuple if you only need it once (gives you the raw iterator). You can use this to create a numpy array if you really want to: arrayOfLists = np.fromiter... More on stackoverflow.com
๐ŸŒ stackoverflow.com
python - List of lists into numpy array - Stack Overflow
How do I convert a simple list of lists into a numpy array? The rows are individual sublists and each row contains the elements in the sublist. More on stackoverflow.com
๐ŸŒ stackoverflow.com
python - How to initialize a numpy array with lists - Stack Overflow
I want to create a np.array filled with lists. The array I want to create is a 2D one. I wonder if there is a way to create this array full of lists kind of like np.zeros((10, 10)) but lists instea... More on stackoverflow.com
๐ŸŒ stackoverflow.com
How do I convert a list to a numpy array?
https://docs.scipy.org/doc/numpy-1.10.4/reference/generated/numpy.asarray.html More on reddit.com
๐ŸŒ r/learnpython
6
1
April 15, 2020
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ convert-python-list-to-numpy-arrays
Convert Python List to numpy Arrays - GeeksforGeeks
July 12, 2025 - Letโ€™s now discuss the different ways of converting a list to an array in more detail. The numpy.array() function is the most common way to convert a list into an array.
Top answer
1 of 11
69

As you discovered, np.array tries to create a 2d array when given something like

 A = np.array([[1,2],[3,4]],dtype=object)

You have apply some tricks to get around this default behavior.

One is to make the sublists variable in length. It can't make a 2d array from these, so it resorts to the object array:

In [43]: A=np.array([[1,2],[],[1,2,3,4]])
In [44]: A
Out[44]: array([[1, 2], [], [1, 2, 3, 4]], dtype=object)

And you can then append values to each of those lists:

In [45]: for i in A: i.append(34)
In [46]: A
Out[46]: array([[1, 2, 34], [34], [1, 2, 3, 4, 34]], dtype=object)

np.empty also creates an object array:

In [47]: A=np.empty((3,),dtype=object)
In [48]: A
Out[48]: array([None, None, None], dtype=object)

But you then have to be careful how you change the elements to lists. np.fill is tempting, but has problems:

In [49]: A.fill([])
In [50]: A
Out[50]: array([[], [], []], dtype=object)
In [51]: for i in A: i.append(34)
In [52]: A
Out[52]: array([[34, 34, 34], [34, 34, 34], [34, 34, 34]], dtype=object)

It turns out that fill puts the same list in all slots, so modifying one modifies all the others. You can get the same problem with a list of lists:

In [53]: B=[[]]*3
In [54]: B
Out[54]: [[], [], []]
In [55]: for i in B: i.append(34)
In [56]: B
Out[56]: [[34, 34, 34], [34, 34, 34], [34, 34, 34]]

The proper way to initial the empty A is with an iteration, e.g.

In [65]: A=np.empty((3,),dtype=object)
In [66]: for i,v in enumerate(A): A[i]=[v,i]
In [67]: A
Out[67]: array([[None, 0], [None, 1], [None, 2]], dtype=object)
In [68]: for v in A: v.append(34)
In [69]: A
Out[69]: array([[None, 0, 34], [None, 1, 34], [None, 2, 34]], dtype=object)

It's a little unclear from the question and comments whether you want to append to the lists, or append lists to the array. I've just demonstrated appending to the lists.

There is an np.append function, which new users often misuse. It isn't a substitute for list append. It is a front end to np.concatenate. It is not an in-place operation; it returns a new array.

Also defining a list to add with it can be tricky:

In [72]: np.append(A,[[1,23]])
Out[72]: array([[None, 0, 34], [None, 1, 34], [None, 2, 34], 1, 23],     dtype=object)

You need to construct another object array to concatenate to the original, e.g.

In [76]: np.append(A,np.empty((1,),dtype=object))
Out[76]: array([[None, 0, 34], [None, 1, 34], [None, 2, 34], None], dtype=object)

In all of this, an array of lists is harder to construct than a list of lists, and no easier, or faster, to manipulate. You have to make it a 2d array of lists to derive some benefit.

In [78]: A[:,None]
Out[78]: 
array([[[None, 0, 34]],
       [[None, 1, 34]],
       [[None, 2, 34]]], dtype=object)

You can reshape, transpose, etc an object array, where as creating and manipulating a list of lists of lists gets more complicated.

In [79]: A[:,None].tolist()
Out[79]: [[[None, 0, 34]], [[None, 1, 34]], [[None, 2, 34]]]

===

As shown in https://stackoverflow.com/a/57364472/901925, np.frompyfunc is a good tool for creating an array of objects.

np.frompyfunc(list, 0, 1)(np.empty((3,2), dtype=object))  
2 of 11
10

If you really need a 1-d array of lists you will have to wrap your lists in your own class as numpy will always try to convert your lists to arrays inside of an array (which is more efficient but obviously requires constant size-elements), for example through

class mylist:

    def __init__(self, l):
        self.l=l

    def __repr__(self): 
        return repr(self.l)

    def append(self, x):
        self.l.append(x)

and then you can change any element without changing the dimension of others

>>> x = mylist([1,2,3])
>>> y = mylist([1,2,3])
>>> import numpy as np
>>> data = np.array([x,y])
>>> data
array([[1,2,3], [1,2,3]], dtype=object)
>>> data[0].append(2)
>>> data
array([[1,2,3,2], [1,2,3]], dtype=object)

Update

As suggested by ali_m there is actually a way to force numpy to simply create a 1-d array for references and then feed them with actual lists

>>> data = np.empty(2, dtype=np.object)
>>> data[:] = [1, 2, 3], [1, 2, 3]
>>> data
array([[1, 2, 3], [1, 2, 3]], dtype=object)
>>> data[0].append(4)
>>> data
array([[1, 2, 3, 4], [1, 2, 3]], dtype=object)
๐ŸŒ
APXML
apxml.com โ€บ courses โ€บ essential-numpy-pandas โ€บ chapter-2-getting-started-numpy-arrays โ€บ creating-arrays-from-lists
NumPy Array from Python List
Here, the list of three lists, each containing three integers, is transformed into a 2-dimensional array (a matrix) with 3 rows and 3 columns. NumPy arranges the data accordingly. Transformation of a nested Python list into a 2D NumPy ndarray. For NumPy to create a standard multi-dimensional array efficiently, the inner lists must have the same length.
๐ŸŒ
APXML
apxml.com โ€บ courses โ€บ linear-algebra-fundamentals-ml โ€บ chapter-2-numpy-numerical-computing โ€บ creating-numpy-arrays
Creating NumPy Arrays
The most straightforward way to create a NumPy array is by converting an existing Python list or tuple using the np.array() function. NumPy intelligently infers the data type (like integer or floating-point) from the list elements, but you can also specify it explicitly.
Find elsewhere
๐ŸŒ
NumPy
numpy.org โ€บ devdocs โ€บ user โ€บ basics.creation.html
Array creation โ€” NumPy v2.6.dev0 Manual
numpy.ones, numpy.zeros, and random define arrays based upon the desired shape. The ndarray creation functions can create arrays with any dimension by specifying how many dimensions and length along that dimension in a tuple or list.
๐ŸŒ
Python Like You Mean It
pythonlikeyoumeanit.com โ€บ Module3_IntroducingNumpy โ€บ FunctionsForCreatingNumpyArrays.html
Functions for Creating NumPy Arrays โ€” Python Like You Mean It
You can create an array from a Python list or tuple by using NumPyโ€™s array function. NumPy will interpret the structure of the data it receives to determine the dimensionality and shape of the array.
๐ŸŒ
Saturn Cloud
saturncloud.io โ€บ blog โ€บ how-to-initialize-numpy-array-of-list-objects-a-comprehensive-guide
How to Initialize Numpy Array of List Objects: A Guide | Saturn Cloud Blog
May 1, 2026 - Initializing a Numpy array of list objects is a simple process that can greatly optimize your data science projects. Remember, the key steps are to import the Numpy library, create your list or lists, convert the list to a Numpy array using np.arr...
๐ŸŒ
DEV Community
dev.to โ€บ arasosman โ€บ how-to-create-numpy-arrays-from-lists-5bpm
How to Create NumPy Arrays from Lists - DEV Community
August 9, 2025 - import numpy as np # Basic conversion python_list = [1, 2, 3, 4, 5] array = np.array(python_list) print(array) # [1 2 3 4 5] # 2D arrays from nested lists matrix_list = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] matrix = np.array(matrix_list) print(matrix) # [[1 2 3] # [4 5 6] # [7 8 9]] # Specify data type explicitly float_array = np.array([1, 2, 3], dtype=np.float32) print(float_array) # [1. 2. 3.] # From list of tuples coordinates = [(1, 2), (3, 4), (5, 6)] coord_array = np.array(coordinates) print(coord_array.shape) # (3, 2) # Mixed types get promoted mixed = [1, 2.5, 3] mixed_array = np.array(mixed) print(mixed_array.dtype) # float64 # Creating arrays of objects objects = ['hello', 42, [1, 2, 3]] obj_array = np.array(objects, dtype=object) ... Master NumPy array reshaping, explore NumPy's mathematical functions, and dive into scientific computing with Python.
๐ŸŒ
Programiz
programiz.com โ€บ python-programming โ€บ numpy โ€บ array-creation
NumPy Array Creation (With Examples)
June 1, 2023 - In the above example, we first imported the numpy library as np and created a list named list1. Notice the code ... Here, we have created an array by passing list1 as an argument to the np.array() function.
๐ŸŒ
NumPy
numpy.org โ€บ doc โ€บ 2.0 โ€บ user โ€บ basics.creation.html
Array creation โ€” NumPy v2.0 Manual
The ndarray creation functions e.g. numpy.ones, numpy.zeros, and random define arrays based upon the desired shape. The ndarray creation functions can create arrays with any dimension by specifying how many dimensions and length along that dimension in a tuple or list.
๐ŸŒ
Towards Data Science
towardsdatascience.com โ€บ home โ€บ artificial intelligence โ€บ here are 30 ways that will make you a pro at creating numpy arrays
Here Are 30 Ways That Will Make You a Pro at Creating NumPy Arrays | Towards Data Science
August 31, 2022 - To create a 2-dimensional NumPy array from a list of lists, once again, you can use the [np.array()](https://numpy.org/doc/stable/reference/generated/numpy.array.html) method as above.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ numpy โ€บ different-ways-to-create-numpy-arrays-in-python
Different Ways to Create Numpy Arrays in Python - GeeksforGeeks
January 31, 2026 - The simplest way to create a NumPy array is by passing a Python list or tuple to the numpy.array() function.
๐ŸŒ
Note.nkmk.me
note.nkmk.me โ€บ home โ€บ python โ€บ numpy
Convert between NumPy array and Python list | note.nkmk.me
January 23, 2024 - The tolist() method returns a nested list structure that mirrors the number of dimensions in the original ndarray. In the following examples, the NumPy arrays are created using arange() and reshape().
๐ŸŒ
NumPy
numpy.org โ€บ doc โ€บ stable โ€บ reference โ€บ routines.array-creation.html
Array creation routines โ€” NumPy v2.5 Manual
empty(shape[, dtype, order, device, like]) ยท Return a new array of given shape and type, without initializing entries