I'm new to Python and my problem is how to construct a matrix from some lists? For example if i have lists:
[388.625, 174.125, 157.25, 166.375]
[432.25, 606.125, 326.25, 202.75]
[383.5, 718.25, 630., 284.]
[487.375, 299.125, 438.125, 432.5]
How can i join them to create a matrix?
Assuming that by "matrix" you mean a 2-D numpy
array,
import numpy
matrix = numpy.array(list_of_lists)
will do it, if in list_of_lists
you have, guess what!, the list of lists of numbers.
If what you have is, eg, four separate lists, each of four numbers, named a
, b
, c
and d
, making a list of lists out of them isn't really all that hard...:
matrix = numpy.array([a, b, c, d])
and so forth, depending exactly on what you mean by "construct a matrix from some lists"!-)
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.