Python scientific computing learns a NumPy fast processing data

Source: Internet
Author: User

1 Creating an array

(1) Array (boject, Dtype=none, Copy=true, Order=none, Subok=false, ndmin=0)

A = Array ([1, 2, 3, 4])

b = Array ([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]])

A.dtype-Dtype (' int32 ')

A.shape---(4,)

B.shape---(3, 4)

a.shape=2, 1 # (-1 when automatically calculated, equivalent to 2, 6)

c = A.reshape ((2,2)) #c和a公用一个空间

(2) Arange ([Start,] stop [, step], Dtype=none)

A = Arange (5)-->array ([0, 1, 2, 3, 4])

A[2:4]-->array ([2,3])

A[:-1]-->array ([0, 1, 2, 3]) #下标为负数, indicating the number of forwards from the back

A[2:4] = 4,-->array ([0, 1,]) #可以通过下标修改元素

x = Arange (5, 0,-1)-->array ([5, 4, 3, 2, 1])

X[array ([True, False, True, false])]

-->array ([5, 3]) #只获取布尔数组中True所在的下标 0 2 length not counted false

X[array ([True, False, False, True, false])) = -5, 2 #用布尔数组修改True所在下标的元素

x-->array ([-5, 4, 3,-2, 1])

(3) Linspace (Start, Stop, num=50, Endpoint=true, Retstep=false) #等差数列的一维数组

Logspane (Start, Stop, num=50, Endpoint=true, base=10) #等比数列的一维数组

(4) Frombuffer

FromFile

FromString (String, Dtype=float, Count=-1, sep= ")

FromString (' abcdefgh ', int8)

-->array ([98, 101, 102, 103, 104], dtype=int8) #一个字符占1个字节 (Byte) = 8 bit (bit),

FromString (' abcdefgh ', In16)

-->array ([25185, 25699, 26213, 26727], dtype=int16) #25185 =98*256 + 97

(5) FromFunction (funtion, Shape, **kwargs)


def func (I, J):

Return (i+1) * (j+1)

A = FromFunction (func, (9, 9))--generates a 99 multiplication Formula two-dimensional array a[i, j] = func (i, J)

The above is equivalent to Arange (1,10). Reashape ( -1,1) * Arange (1,10)

Python scientific computing learns a NumPy fast processing data

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.