user_docs
array
import numpy as np
array( object , dtype= None , copy= True , order= 'K' , subok= False , ndmin= 0 )
nd = np. array( ( 1 , 2 , 3 , 4 ) )
nd. dtype
nd. ndim
np. array( ( [ 1 , 2 , 3 , ] [ 1 , 2 ] ) )
order C np.array([range(1,4),range(4,8)],order=‘C’)
order F np.array([range(1,4),range(4,8)],order=‘F’)
ndarray
np. ndarray( ( 2 , 2 ) , buffer = np. array( range ( 4 ) ) , dtype= int )
. shape
. size
. dtype
. data
. reshape( m, n)
a[ : ]
b[ [ 0 , 1 ] ]
b[ : : , 1 ]
b[ [ 1 , 2 ] , [ 1 , 2 ] ] ?
b[ : : , [ 1 , 4 ] , b[ : : , : : 2 ] ]
create ndarray ways
np. zeros( )
np. zeros_like/ ones_likes/ empty_like( a, . . . )
full( shape, fill, dtype, order)
arange( start, stop, step, stype)
linspace( start, stop, num= 50 )
random. rand/ randn( d0, d1. . . )
random. randint( low, high, size)
np. typeDict
np. typecodes
np. typeNA
create data type
1. date: name, age, eg.[(‘sun’, 10), (‘yang’, 11)]
dt = np. dtype( 'U16' , 'i4' )
a = np. array( [ ( 'sun' , 10 ) , ( 'yang' , 11 ) ] , dtype= dt)
a[ 'f0' ]
a[ 'f1' ]
dt = np. dtype( '3S8' , '' )
2. second way
dt = np. dtype( [ ( 'name' , 'U16' ) , ( 'age' , 'i4' ) ] )
3. third way
dt = np. dtype( [ 'f0' , [ ( 'f1' , 'U2' ) , ( 'f2' , np. int16) ] ] )
dt = np. dtype( [ ( 'name' , 'U16' ) , ( 'age' , 'i4' ) ] )
dt = np. dtype( { 'x' : ( 'S2' , 0 ) , 'y' : ( 'i4' , 2 ) } )
dt = np. dtype( { 'name' : [ 'name' , 'age' ] , 'formats' : [ 'U16' , 'i4' ] } )
calculate
np. any
np. all
np. where( cond, [ x, y] )
&
|
np. all
np. arange( 9 ) . reshape( 3 , 3 )
np. indices( a. shape)
r, c = np. indices( a. shape)