List comprehension
Using a list comprehension:[x for x in iterable] to create list instance
[Expresion for x in Iterabel] lists the core of the derivation in expression.
1 #!/usr/bin/env Python32 #-*-coding:utf-8-*-3 ############################4 #File Name:test_list_comprehension.py5 #Author:frank6 #Mail: [email protected]7 #Created time:2018-05-29 20:33:568 ############################9 ImportNumPy as NPTen OneSeed = 123 A - #Analog Data Set labels - #generate random numbers based on seed theRDG =np.random.RandomState (Seed) - #sir, a random number matrix of 5 rows and 2 columns. -X = Rdg.rand (5,2) - #each time a row is taken, judging if two numbers and less than 1, give a value of 1; If two numbers and not less than 1, assign a value to a + #[expression for x in Iterable] -Y = [[Int (x0+x1<1)] for(X0,X1)inchX] + Print("x:{}". Format (X)) A Print("y:{}". Format (Y))
The list-pushing derivation has a strong extensibility, and expression differs, and the functions that can be executed are quite different.
Python-list comprehension