如何在数组的一部分与数组的一部分之间进行操作?

时间:2017-06-04 00:52:22

标签: python python-2.7 loops

<html>

<head>

<title>Question 2</title>

<script src="question2.js" type="text/javascript"></script>

<head>
<body>

<div class="funky"></div>

</body>

<html>

var ROWS = 10;
var COLS = 10;

function go() {
var out = document.getElementsByClassName("funky")[0];

var table = document.createElement("table");

table.border = 1;

for (var i=0; i <= ROWS; i += 1) {

var row = document.createElement("row");

if (i == 2) {

row.Fontweight = "bold";

}

for (var j=0; j < COLS; j += 2) {

var col = document.createElement("cell");

col.innerHTML = i + " " +  j;

if (j/2 == 0) {

col.style.color = "purple";

}
row.appendChild(col)

} 

table.appendChild(row);

}

}

这只是我的问题的一个简单示例。因此无法使用组来完成。我需要一个循环来解决这个问题。

1 个答案:

答案 0 :(得分:0)

你可以重塑阵列a,对其进行操作而不是压扁。

In [24]: import numpy as np

In [25]: a=np.array([2,3,4,6,7,4,5,3,2,1,9,8,7,6,4,2])

In [26]: b=np.array([1,5,3,7])

In [27]: (a.reshape(4,4).T - b).T.ravel()
Out[27]: array([ 1,  2,  3,  5,  2, -1,  0, -2, -1, -2,  6,  5,  0, -1, -3, -5])
相关问题