程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python data analysis - 1

編輯:Python

(●’◡’●)



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. 

ndarray

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
(●’◡’●)


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved