0

# cannot adding from one array to another

#----------program----------- n = np.array([i/10 for i in range(10)]) weight_a = [i * 0 for i in range(10)] # creating weights weight_b = [i * 0 for i in range(10)] weight_c = [i * 0 for i in range(10)] m2 = np.array([weight_a, weight_b, weight_c]).transpose() print(n) for i, j in enumerate(n): # i = index , j = data m2[i][0] += j print(m2) #---------------------- when I print m2 the answer is still 0, n array elements not adding up in m2 array thankyou

6 Answers

+ 1

i solved it by creating weights by
weights = np.zeros(10)
instead of creating them in a list

0

Please give an example what the output should look like.
same question:
https://www.sololearn.com/Discuss/3086625/?ref=app

0

Lisa
#---------program--------------------
n = np.array([i/10 for i in range(10)])
weight_a = [i * 0 for i in range(10)] # creating weights
weight_b = [i * 0 for i in range(10)]
weight_c = [i * 0 for i in range(10)]
m2 = np.array([weight_a, weight_b, weight_c]).transpose()
print(n)
m2 = m2.transpose()
m2[0] = m2[0] + n
print(m2)
#-------output---------------------
[0. 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9]
[[0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0]]
#---------expected output---------
[0. 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9]
[[0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9]
[0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0]]
thanks for helping

0

In array all rows must have the same number of columns. If you don't want that, use a nested list

0

Lisa i cannot use a nested list as i have to do dot product of 2 arrays later in the program

0

Lisa if the n array have integers then it can add to m2 array but if n array have floats it is not adding up to m2 array