arrays

Python assign covariance row wise calculation

Python assign covariance row wise calculation Question: I am trying to assign the covariance value to a column based on the dataframe I have. The df is ~400k records x 30+ columns. The two data series that act as inputs for COV() are all aligned as a single record (with ~400k records). I would like …

Total answers: 1

Python Membership Initialisation

Python Membership Initialisation Question: I fail to define an array in my InitializeMembershipWeight function. I am currently working on a C-Means clustering algorithm. #Membership Initialisation def initializeMembershipWeights(): weight = np.random.dirichlet(np.ones(k),n) weight_array = np.array(weight) return weight_array print(weight_array) NameError Traceback (most recent call last) <ipython-input-114-70f058bffa58> in <module> —-> 1 print(weight_array) NameError: name ‘weight_array’ is not defined Asked …

Total answers: 1

How can I sum several variables in numpy array?

How can I sum several variables in numpy array? Question: I have a numpy array, it looks like this: test = numpy.array([0, 0, 1, 3, 5, 0, 0, 0, 15, 16, 2, 0, 0]) I would like to get the sum of each "number-cluster": It should be like this: [0 0 0 9 0 0 …

Total answers: 2

How to understand B=np.reshape(A, (a, a, b)) and reverse back by B[:,:,1]

How to understand B=np.reshape(A, (a, a, b)) and reverse back by B[:,:,1] Question: I am quite confused about the following import numpy as np A = np.array([[1,2,3], [2,3,4], [3,4,5]]) A is a 3×3 matrix obviously. Now consider B = np.reshape(A, (3, 3, 1)) B is array([[[1], [2], [3]], [[2], [3], [4]], [[3], [4], [5]]]) If …

Total answers: 1

What is the difference between grid[index] VS grid[index, :] in python

What is the difference between grid[index] VS grid[index, :] in python Question: In this https://colab.research.google.com/drive/1gS2aJo711XJodqqPIVIbzgX1ktZzS8d8?usp=sharing , they used np.max(qtable[new_state, :]) But I did an experiment and I don’t understand the need of : . My experiement show the same value, same array shape import numpy as np N = 10 grid = np.array([[np.array(k) for i …

Total answers: 1

How to group items in list in python if the value change?

How to group items in list in python if the value change? Question: Suppose I have a list msg_type =["sent-message", "received-message", "received-message", "sent-message", "received-message", "sent-message", "received-message", "received-message", "sent-message", "sent-message", "received-message", "sent-message", "sent-message", "received-message", "sent-message", "sent-message", "received-message", "sent-message", "received-message", "received-message", "sent-message", "sent-message", "received-message", "sent-message", "received-message", "sent-message", "received-message" ] How would I be able to group this …

Total answers: 2

Python how to count the nested list of lists containing strings

Python how to count the nested list of lists containing strings Question: I have a nested lists of list. I want to know total items in the main and sublists. Then accordingly I want to choose a value for each sublist or item. My code: y = [‘ab’,[‘bc’,’cd’],’ef’] print([len(y[i]) for i in range(len(y))]) alpha=0.5 plot_alpha …

Total answers: 1

Get columns of 2D ndarray defined by index' in another 2D ndarray

Get columns of 2D ndarray defined by index' in another 2D ndarray Question: I have an ndarray arr = np.array([[1,2,3],[4,5,6],[7,8,9]]) and an index-array arr_idx = np.array([[0,2],[1,2],[2,1]]) where each row in arr_idx corresponds to the index of arr which I want to have i.e the result should be [[1,3],[5,6],[9,8]]. Can this be done using numpy-operations? I …

Total answers: 1

Generate an m*n matrix with 1 and 0 (No identity)

Generate an m*n matrix with 1 and 0 (No identity) Question: I need to generate an m*n matrix with 1 and 0 where the sum of each row is 1 and each column is greater than or equal to 1. I’m trying this code but I don’t know how to limit my condition on the …

Total answers: 2