How to iterate over PyTorch tensor
I have a tensor data of size (1000,110) and I want to iterate over the first index of the tensor and calculate the following.
    data = torch.randn(size=(1000,110)).to(device)
    
    male_poor = torch.tensor(0).float().to(device)
    male_rich = torch.tensor(0).float().to(device)
    
    female_poor = torch.tensor(0).float().to(device)
    female_rich = torch.tensor(0).float().to(device)
    
    for i in data:
    
        if torch.argmax(i[64:66]) == 0 and torch.argmax(i[108:110]) == 0:
          female_poor += 1
        if torch.argmax(i[64:66]) == 0 and torch.argmax(i[108:110]) == 1:
          female_rich += 1
        if torch.argmax(i[64:66]) == 1 and torch.argmax(i[108:110]) == 0:
          male_poor += 1
        if torch.argmax(i[64:66]) == 1 and torch.argmax(i[108:110]) == 1:
          male_rich += 1


    disparity = ((female_rich/(female_rich + female_poor))) / ((male_rich/(male_rich + male_poor)))

Is there a faster way than for loop to do this?

The key in pytorch (as well as numpy) is vectorizataion, that is if you can remove loops by operating on matrices it will be a lot faster. Loops in python are quite slow compared to the loops in the underlying compiled C code. On my machine the execution time for your code was about 0.091s, the following vectorized code was about 0.002s so about x50 faster:
import torch
torch.manual_seed(0)
device = torch.device('cpu')

data = torch.randn(size=(1000, 110)).to(device)

import time
t = time.time()
#vectorize over first dimension
argmax64_0 = torch.argmax(data[:, 64:66], dim=1) == 0
argmax64_1 = torch.argmax(data[:, 64:66], dim=1) == 1
argmax108_0 = torch.argmax(data[:, 108:110], dim=1) == 0
argmax108_1 = torch.argmax(data[:, 108:110], dim=1) == 1
female_poor = (argmax64_0 &amp; argmax108_0).sum()
female_rich = (argmax64_0 &amp; argmax108_1).sum()
male_poor = (argmax64_1 &amp; argmax108_0).sum()
male_rich = (argmax64_1 &amp; argmax108_1).sum()

disparity = ((female_rich / (female_rich + female_poor))) / ((male_rich / (male_rich + male_poor)))

print(time.time()-t)
print(disparity)

