I want to convert python 2d list,
[[1,2,3],[4,5,6]]
to
python3 array.array
type,
[ [1 2 3]
[4 5 6] ]
The most important challenge is I wont import numpy
. So I cant use np.asarray()
.
I have also used array.fromlist()
and array.extend()
. Both methods are creating an array of single dimension. But I want to convert multi dimension list to multi dimension array. Is there any way?
What you're asking is not possible. From the array
docs :
This module defines an object type which can compactly represent an array of basic values: characters, integers, floating point numbers ... The type is specified at object creation time by using a type code
The only supported types are as follows (notice the absence of list
):
Type code C Type Python Type
'b' signed char int
'B' unsigned char int
'u' Py_UNICODE Unicode character
'h' signed short int
'H' unsigned short int
'i' signed int int
'I' unsigned int int
'l' signed long int
'L' unsigned long int
'q' signed long long int
'Q' unsigned long long int
'f' float float
'd' double float
It seems like you might be confusing the array
module, with a native implementation of numpy
arrays. This is not the case .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.