Tile (A, reps) method in numpy

Source: Internet
Author: User
Official documentation:

Personal Understanding: Return Value

Ndarray, which returns a multi-digit group after reps repeats...

Parameters

A can be almost all types, array, list, tuple, dict, matrix, Int, long, STR, bool, etc.

Reps, there are many types, such as array, tuple, list, dict, Int, long, And bool. But in any case, it must be a one-dimensional array (not necessarily an array, which is a class one-dimensional array) ", such as [1, 2, 3], (1, 2, 3), or 3.

Implementation Process

1: Set Ndim = a dimension, ndimsa [] = length of each coordinate component of

D = reps length (because reps must be a "class one-dimensional array ")

Ans = tile (a, d), ndimsans [] = the length of each coordinate component of ANS

2: ANS. Ndim = max (A. Ndim, d)

If a. Ndim> = D:

For example, ndims = (,), reps =)

So ndims [] remains unchanged. Add a. Ndim-D '1' before the reps array, then reps =)

Otherwise, A. Ndim <D:

For example, ndims = (2, 3), reps = (1, 2, 3, 4)

At this time, the ndims dimension is not enough, you should add the dimension to D, similarly add the d-A.ndims before ndims '1', that is, ndims)

3: Calculate ndimsans []

Because ndims and reps have the same length through 2, ndimsans = (ndism [0] * reps [0], ndims [1] * reps [1], ndims [2] * reps [2],...) multiply the index value

For example, ndims = (,), reps =)

So ndimsans = (2*1, 3*1, 4*2) =)

4: Calculate ans

The dimension size of ANS is determined through 2, and the length of each dimension component of ANS is determined through 3.

Note that the repetition of dimensions starts from the right side (which can be understood as from the low dimension). For details, see the following example.

Example:

>>> A = array ([[1, 2], [3, 4])

>>>
Array ([[1, 2],
[3, 4])
>>> Reps = (1, 2, 3)
>>> Ans = tile (A, reps)
>>> Ans
Array ([[1, 2, 1, 2, 1, 2],
[3, 4, 3, 4, 3, 4],
[1, 2, 1, 2, 1, 2],
[3, 4, 3, 4, 3, 4])

>>> Ans. Shape
(1, 4, 6)

From a low dimension, repeat the column three times to obtain a' = [1, 2, 2, 2],

[3, 4, 3, 4]

Repeat the previous steps twice to obtain a ''= [[1, 2, 2, 2],

[3, 4, 3, 4],

[1, 2, 1, 2],

[3, 4, 3, 4]

Repeat the last layer once (unchanged), ANS = [[1, 2, 1, 2],

[3, 4, 3, 4],

[1, 2, 1, 2],

[3, 4, 3, 4]

Therefore, there is a 3-dimensional array (, 6) at most.

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.