Matrix Mirroring in python
I would like to stick to basic Python packages like numpy. Thanks in advance for any help!!
7 Answers 7
This can be accomplished using a simple helper function in pure python:
Obviously, once the mirrored list is created, you can use it to create a numpy array or whatever.
![]()
Use numpy.lib.pad with ‘reflect’
I have added step by step transformation. flipud and flipud refrence
This is tagged numpy so I’ll assume your matrix is a 2d array
flipping it on the rows:
removing the duplicate first line
Do you think you can do the same with a horizontal (column) reversal and concatenate (axis=1)?
And here is a non-numpy solution:
![]()
Suppose you have
You can invert this along the first (vertical) axis via
where ::-1 selects the rows from last to first in steps of -1 .
To omit the last row, explicitly ask for the selection to stop immediately before 0 :
This can then be concatenated along the first axis
This can be repeated along the other axis too:
-
The Overflow Blog
Related
Hot Network Questions
Subscribe to RSS
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.
Site design / logo © 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA . rev 2023.3.11.43304
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.
numpy.flip#
Reverse the order of elements in an array along the given axis.
The shape of the array is preserved, but the elements are reordered.
New in version 1.12.0.
axis None or int or tuple of ints, optional
Axis or axes along which to flip over. The default, axis=None, will flip over all of the axes of the input array. If axis is negative it counts from the last to the first axis.
If axis is a tuple of ints, flipping is performed on all of the axes specified in the tuple.
Changed in version 1.15.0: None and tuples of axes are supported
A view of m with the entries of axis reversed. Since a view is returned, this operation is done in constant time.
Flip an array vertically (axis=0).
Flip an array horizontally (axis=1).
flip(m, 0) is equivalent to flipud(m).
flip(m, 1) is equivalent to fliplr(m).
flip(m, n) corresponds to m[. -1. ] with ::-1 at position n.
flip(m) corresponds to m[::-1. -1. -1] with ::-1 at all positions.
flip(m, (0, 1)) corresponds to m[::-1. -1. ] with ::-1 at position 0 and position 1.
Зеркальное отображение матриц в питоне
Я хотел бы придерживаться базовых пакетов Python, таких как numpy. Заранее благодарю за любую помощь!!
7 ответов
Это можно выполнить с помощью простой вспомогательной функции в чистом питоне:
Очевидно, что после создания зеркального списка вы можете использовать его для создания массива numpy или любого другого.
Использовать numpy.lib.pad с помощью ‘reflect’
Я добавил шаг за шагом трансформацию. flipud и flipud refrence
Предположим, что у вас есть
Вы можете инвертировать это вдоль первой (вертикальной) оси через
где ::-1 выбирает строки от последнего до первого с шагом -1 .
Чтобы опустить последнюю строку, явным образом попрошу, чтобы выбор останавливался непосредственно перед 0 :
Как отзеркалить матрицу в python
I would like to stick to basic Python packages like numpy. Thanks in advance for any help!!
![]()
7 Answers 7
This can be accomplished using a simple helper function in pure python:
Obviously, once the mirrored list is created, you can use it to create a numpy array or whatever.
![]()
Use numpy.lib.pad with ‘reflect’
I have added step by step transformation. flipud and flipud refrence
And here is a non-numpy solution:
![]()
Suppose you have
You can invert this along the first (vertical) axis via
where ::-1 selects the rows from last to first in steps of -1 .
To omit the last row, explicitly ask for the selection to stop immediately before 0 :
This can then be concatenated along the first axis
This can be repeated along the other axis too:
This is tagged numpy so I’ll assume your matrix is a 2d array
flipping it on the rows:
removing the duplicate first line
Do you think you can do the same with a horizontal (column) reversal and concatenate (axis=1)?
Как отзеркалить матрицу в python
Дана матрица NXM, состоящая из натуральных чисел Зеркально отразить ее элементы относительно вертикальной оси симметрии
Здравствуйте, помогите, пожалуйста, написать программы на данные задания и блок-схемы 2. Дана.
Дана квадратная случайная матрица. Зеркально отразить ее элементы относительно побочной диагонали
package com.company; import java.lang.String; import java.util.Random; class Main < .