Time: 2014.06.25
Location: Base
---------------------------------------------------------------------------------
I. Brief Introduction
Numpy. asarray (a, dtype = None, order = None)
Function Description: converts input data (list of lists, tuples, lists of tuples, and so on) to a matrix.
A: array-based input data, including list, list of tuples, lists of tuples, and ndarrays
Dtype:
The data type is derived from the input data.
---------------------------------------------------------------------------------
Ii. instance 2.1 converts the list to an array
from numpy import asarraymy_list=[1,2,3,4]asarray(my_list)
Output: array ([1, 2, 3, 4]) Note: asarray does not process or copy data that is already an array. It can be verified as follows:
from numpy import arrayarray([1,2,3,4])asarray(a) is a
Output: True
Note: When dtype is set, only dtpye data is copied when not at the same time, for example:
A = array ([1, 2, 4], dtype = numpy. float32) asarray (a, dtype = numpy. float32) is a # output Trueasarray (a, dtype = numpy. float64) is a # output False
2.2 convert the list to a matrix
Asarray ([1 ., 2], [3, 4], [5, 6]) asarray ([1 ., 2], [3, 4], [5, 6]). shape # output (3, 2) asarray ([1 ., 2], [3, 4], [5, 6]) [] # The value of column 0 in the second row is 5.
2.3 convert the list of tuples to a matrixasarray([(1,2,3),(4,5,6),(7,8,9)])