Move values around the matrix perimeter - Python / NumPy

时间:2017-08-30 20:26:26

标签: python numpy

it's necessary that lateral values ​​are shifted along the perimeter.

E.g. one step twist:

1 2 3     4 1 2
4 5 6 ==> 7 5 3
7 8 9 8 9 6

2 个答案:

答案 0 :(得分:1)

Here's one approach for body { max-width: 500px; } #top-background-flag { border-top: 2px solid #C2C2C2; background: linear-gradient( to bottom right, #5DCAD3 50%, transparent 50.5% ) no-repeat bottom, /* bottom part */ linear-gradient(100deg, #5DCAD3, #5DCAD3) no-repeat top; /* top portion */ padding-bottom: 3.5rem; border-bottom: 2px solid #C2C2C2; background-size: 100% 3rem, 100% calc(100% - 3rem); position: relative; } #top-background-flag:after { content: ''; border-bottom: 1px solid red; border-top: 1px solid red; position: absolute; width: 100%; bottom: 22px; left: 0; transform: rotate(-5.5deg); } arrays -

<div id=top-background-flag>
  A fun title
</div>

Sample runs -

$producttype = $_GET['ProductType'];
$businessunit = $_GET['BusinessUnit'];
$products = new WP_Query( array( 
  'post_type' => 'products',
  'posts_per_page' => 15,
  'orderby' => 'title',
  'order'   => 'ASC',
  'paged' => $paged,
  'tax_query' => array(
    'relation' => 'OR',
     array(
       'taxonomy' => 'producttype',
       'field' => 'name',
       'term' => $producttype
     ),
     array(
       'taxonomy' => 'businessunit',
       'field' => 'name',
       'term' => $businessunit
     )
  )
)

答案 1 :(得分:1)

通过指数。

a = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
indexes = (np.array([0, 0, 0, 1, 2, 2, 2, 1]), np.array([0, 1, 2, 2, 2, 1, 0, 0]))
values = np.array([1, 2, 3, 6, 9, 8, 7, 4])
values = np.roll(values, 1)
a[indexes] = values
np.roll ...

为了简化说明,我用手打印了索引。