Why aren't the values from the for loop appending to the array?

I’m trying to append values from a for loop into a numpy array. While the values are correct, the array only returns none values. The values entered are from another numpy array. import numpy as np import matplotlib.pyplot as plt j=np.array([14,15,16,16,16,22,22,24,24,25,25,25,25,25]) u=np.unique(j) def P(age): sum=0 for i in range(14): if j[i]==age: sum=sum+1 else: sum=sum print(sum/14)… Read More Why aren't the values from the for loop appending to the array?

Add the same value to every row in a numpy array

I have a numpy array that looks like this: [[0.67058825 0.43529415 0.33725491] [0.01568628 0.30980393 0.96862751] [0.24705884 0.63529414 0.29411766] [0.27843139 0.63137257 0.37647063] [0.26274511 0.627451 0.33333334] [0.25098041 0.61960787 0.30980393]] I want to add a 1 to every row like this: [[0.67058825 0.43529415 0.33725491 1] [0.01568628 0.30980393 0.96862751 1] [0.24705884 0.63529414 0.29411766 1] [0.27843139 0.63137257 0.37647063 1] [0.26274511… Read More Add the same value to every row in a numpy array

How to remove numpy array row which matches the string in list

I have got an array which looks like array = array([[‘Mango’, 0.75, 0.25], [‘Honey’, 0.75, 0.25], [‘Grape’, 0.625, 0.375], [‘Pineapple’, 0.5, 0.5]], dtype=object) and a list item = {‘Honey’,’Grape’} now, have to remove the rows from the array which matches the items in the list. Expected Output: array = array([[‘Mango’, 0.75, 0.25], [‘Pineapple’, 0.5, 0.5]],… Read More How to remove numpy array row which matches the string in list