Function iasub2ind

namespace:ia636
page:iasub2ind

Synopse

Convert linear double subscripts to linear index.

  • i = iasub2ind(dim, x, y)
    • i: Image.
    • dim: Image. Dimension.
    • x: Image. x index.
    • y: Image. y index.
1. from numpy import *
2. 
3. def iasub2ind(dim, x, y):
4. 
5.     x, y = asarray(x), asarray(y)
6.     i = x*dim[1] + y
7.     i = i.astype(int32)
8.     return i

Examples

Example 1

01. from ia636 import iasub2ind
02. 
03. f = array([[0,6,0,2],[4,0,1,8],[0,0,3,0]])
04. print f
05. x=[0,0,1,2,2,2]
06. y=[0,2,1,0,1,3]
07. print x
08. print y
09. i = iasub2ind(f.shape, x, y)
10. print i
11. put(f, i, 10)
12. print f
[[0 6 0 2]
 [4 0 1 8]
 [0 0 3 0]]
[0, 0, 1, 2, 2, 2]
[0, 2, 1, 0, 1, 3]
[ 0  2  5  8  9 11]
[[10  6 10  2]
 [ 4 10  1  8]
 [10 10  3 10]]