# [Numpy-discussion] indexed arrays ignoring duplicates

Damien Morton dmorton@bitfurnace....
Wed Sep 29 01:01:06 CDT 2010

```lets say i have arrays:

a = array((1,2,3,4,5))
indices = array((1,1,1,1))

and i perform operation:

a[indices] += 1

the result is

array([1, 3, 3, 4, 5])

in other words, the duplicates in indices are ignored

if I wanted the duplicates not to be ignored, resulting in:

array([1, 6, 3, 4, 5])

the example above is somewhat trivial, what follows is exactly what I
am trying to do:

def inflate(self,pressure):
faceforces = pressure *
cross(self.verts[self.faces[:,1]]-self.verts[self.faces[:,0]],
self.verts[self.faces[:,2]]-self.verts[self.faces[:,0]])
self.verts[self.faces[:,0]] += faceforces
self.verts[self.faces[:,1]] += faceforces
self.verts[self.faces[:,2]] += faceforces

def constrain_lengths(self):
vectors = self.verts[self.constraints[:,1]] -
self.verts[self.constraints[:,0]]
lengths = sqrt(sum(square(vectors), axis=1))
correction = 0.5 * (vectors.T * (1 - (self.restlengths / lengths))).T
self.verts[self.constraints[:,0]] += correction
self.verts[self.constraints[:,1]] -= correction

def compute_normals(self):
facenormals =
cross(self.verts[self.faces[:,1]]-self.verts[self.faces[:,0]],
self.verts[self.faces[:,2]]-self.verts[self.faces[:,0]])
self.normals.fill(0)
self.normals[self.faces[:,0]] += facenormals
self.normals[self.faces[:,1]] += facenormals
self.normals[self.faces[:,2]] += facenormals
lengths = sqrt(sum(square(self.normals), axis=1))
self.normals = (self.normals.T / lengths).T

Ive been getting some very buggy results as a result of duplicates
being ignored in my indexed inplace add/sub operations.
```