Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23131

Adding value to 2d numpy array based on condition

$
0
0

Having trouble manipulating a 2D numpy array (below). I'm using np.where to add a value if the given condition is met, but doesn't seem to be working. Is this simply not possible or am I making a simple mistake?

a = ['circle','square']b=['north','south']c=['red','blue']d=['long','short']x = []for shape in a:  for direction in b:    for color in c:      for length in d:        x.append([shape, direction, color, length, 0])x = np.array(x)# conditional add - if condition is met, add 1 to numeric index, else assign value of 2x[:,4] = np.where((x[:,0]=='circle') & (x[:,1]=='south'), x[:,4]+1, 2)

Viewing all articles
Browse latest Browse all 23131

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>