(●’◡’●)
Homework :
use numpy Create a two-dimensional or multi-dimensional normally distributed random number , Retention compliance [0, 1) Number of numbers , Then average
import numpy as np # Import numpy library , Alias np
a=np.random.randn(4,2) # Create a normal distribution random number with four rows and two columns
b=a[(a>=0)&(a<1)] # Take out >=0 also <1 The random number , And assign it to b
print("a",a)
print("b",b)
print(b.mean()) # Average.
One ndarray Are items of the same type and size ( Usually fixed size ) Multidimensional containers . The size and the number of items in the array are determined by its shape Definition , It is from N Composed of non negative integers tuple( Tuples ), Used to specify the size of each dimension . The types of items in the array are determined by separate data-type object (dtype) Appoint , One with each ndarray Related to .
The difference is ,ndarrays Can share the same data , So in a ndarray Changes made in may be visible in another .
Size is 2 x 3 Two dimensional array of , from 4 An integer element of bytes :
>>> x = np.array([[1, 2, 3], [4, 5, 6]], np.int32)
>>> type(x)
<type 'numpy.ndarray'>
>>> x.shape
(2, 3)
>>> x.dtype
dtype('int32')
Other commonly used methods can be referred to
(●’◡’●)
【Python】 newspaper :lxml.etree
Hello everyone , I am a Python
List of articles effect Code