Python Scientific Computing Library numpy-tile function

Source: Internet
Author: User
Tags function prototype repetition

In the process of learning KNN classification algorithm using the tile function, there are many do not understand, recorded the use of this function.

Function prototype: Numpy.tile (a,reps) #简单理解是此函数将A进行重复输出

Where a and reps are parameters of array_like, a can be: Array,list,tuple,dict,matrix and basic data type int,string,float and bool type, reps type can be tuple,list , Dict,array,int,bool, but cannot be a float,string,matrix type.

There are two kinds of common forms, which is a simple one-dimensional repetitive output, and a two-dimensional repetition after the output.

One-dimensional repetition:

1 ImportNumPy as NP2A = [[1,2,3],[4,5,5]]3b = Np.tile (A,3)4 Print(b)5 6 #output to7 #[[1 2 3 1 2 3 1 2 3]8 #[4 5 5 4 5 5 4 5 5]]

Two-dimensional repetition: #上面的一维重复相当于 B = np.tile (a,[1,3])

1 ImportNumPy as NP2A = [[1,2,3],[4,5,5]]3b = Np.tile (A,[2,3])4 Print(b)5 6 #the output is:7 #[[1 2 3 1 2 3 1 2 3]8 #[4 5 5 4 5 5 4 5 5]9 #[1 2 3 1 2 3 1 2 3]Ten # [4 5 5 4 5 5 4 5 5]]

Python Scientific Computing Library numpy-tile function

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.