本文整理汇总了Java中ucar.ma2.IndexIterator.next方法的典型用法代码示例。如果您正苦于以下问题:Java IndexIterator.next方法的具体用法?Java IndexIterator.next怎么用?Java IndexIterator.next使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ucar.ma2.IndexIterator
的用法示例。
在下文中一共展示了IndexIterator.next方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: identity
import ucar.ma2.IndexIterator; //导入方法依赖的package包/类
/**
* Return the identity array - a square array with ones on the main
* diagonal.
*
* @param n Number of rows (and columns) in n x n output.
* @param dtype Data type
* @return Identity array
*/
public static Array identity(int n, String dtype) {
DataType dt = toDataType(dtype);
int[] shape = new int[]{n, n};
Array a = Array.factory(dt, shape);
IndexIterator index = a.getIndexIterator();
int[] current;
while (index.hasNext()) {
index.next();
current = index.getCurrentCounter();
if (current[0] == current[1]) {
index.setObjectCurrent(1);
} else {
index.setObjectCurrent(0);
}
}
return a;
}
示例2: eye
import ucar.ma2.IndexIterator; //导入方法依赖的package包/类
/**
* Return a 2-D array with ones on the diagonal and zeros elsewhere.
*
* @param n Number of rows in the output.
* @param m Number of columns in the output.
* @param k Index of the diagonal: 0 (the default) refers to the main
* diagonal, a positive value refers to an upper diagonal, and a negative
* value to a lower diagonal.
* @param dtype Data type
* @return Created array
*/
public static Array eye(int n, int m, int k, String dtype) {
DataType dt = toDataType(dtype);
int[] shape = new int[]{n, m};
Array a = Array.factory(dt, shape);
IndexIterator index = a.getIndexIterator();
int[] current;
int i, j;
while (index.hasNext()) {
index.next();
current = index.getCurrentCounter();
i = current[0];
j = current[1] - k;
if (i == j) {
index.setObjectCurrent(1);
} else {
index.setObjectCurrent(0);
}
}
return a;
}
示例3: setSection
import ucar.ma2.IndexIterator; //导入方法依赖的package包/类
/**
* Set section
*
* @param a Array a
* @param ranges Ranges
* @param v Array value
* @return Result array
* @throws InvalidRangeException
*/
public static Array setSection(Array a, List<Range> ranges, Array v) throws InvalidRangeException {
Array r = a.section(ranges);
IndexIterator iter = r.getIndexIterator();
//int[] current;
Index index = v.getIndex();
while (iter.hasNext()) {
iter.next();
//current = iter.getCurrentCounter();
//index.set(current);
iter.setObjectCurrent(v.getObject(index));
index.incr();
}
r = Array.factory(a.getDataType(), a.getShape(), r.getStorage());
return r;
}
示例4: take
import ucar.ma2.IndexIterator; //导入方法依赖的package包/类
/**
* Take elements from an array along an axis.
*
* @param a The array
* @param ranges The indices of the values to extract.
* @return The returned array has the same type as a.
*/
public static Array take(Array a, List<Object> ranges) {
int n = a.getRank();
int[] shape = new int[n];
List<List<Integer>> indexlist = new ArrayList<>();
List<Integer> list;
for (int i = 0; i < n; i++) {
Object k = ranges.get(i);
if (k instanceof Range) {
Range kr = (Range) k;
shape[i] = kr.length();
list = new ArrayList<>();
for (int j = kr.first(); j <= kr.last(); j += kr.stride()) {
list.add(j);
}
indexlist.add(list);
} else {
List<Integer> kl = (List<Integer>) k;
shape[i] = kl.size();
indexlist.add(kl);
}
}
Array r = Array.factory(a.getDataType(), shape);
IndexIterator ii = r.getIndexIterator();
int[] current, acurrent = new int[n];
Index index = a.getIndex();
while (ii.hasNext()) {
ii.next();
current = ii.getCurrentCounter();
for (int i = 0; i < n; i++) {
acurrent[i] = indexlist.get(i).get(current[i]);
}
index.set(acurrent);
ii.setObjectCurrent(a.getObject(index));
}
return r;
}
示例5: concatenate
import ucar.ma2.IndexIterator; //导入方法依赖的package包/类
/**
* Concatenate arrays to one array along a axis
*
* @param arrays Array list
* @param axis The axis
* @return Concatenated array
* @throws ucar.ma2.InvalidRangeException
*/
public static Array concatenate(List<Array> arrays, Integer axis) throws InvalidRangeException {
int ndim = arrays.get(0).getRank();
if (axis == -1) {
axis = ndim - 1;
}
int len = 0;
int[] lens = new int[arrays.size()];
int i = 0;
List<Index> indexList = new ArrayList<>();
for (Array a : arrays) {
len += a.getShape()[axis];
lens[i] = len;
indexList.add(Index.factory(a.getShape()));
i += 1;
}
int[] shape = arrays.get(0).getShape();
shape[axis] = len;
Array r = Array.factory(arrays.get(0).getDataType(), shape);
int[] current;
IndexIterator ii = r.getIndexIterator();
Index index;
int idx = 0;
while (ii.hasNext()) {
ii.next();
current = ii.getCurrentCounter();
for (i = 0; i < lens.length; i++) {
if (current[axis] < lens[i]) {
idx = i;
break;
}
}
if (idx > 0) {
current[axis] = current[axis] - lens[idx - 1];
}
index = indexList.get(idx);
index.set(current);
ii.setObjectCurrent(arrays.get(idx).getObject(index));
}
return r;
}