- Joined
- Jan 30, 2023
- Messages
- 6
- Reaction score
- 0
Hi, I want to add new rows to a matrix by a while loop using randomly generated points, but I am getting an error code regarding number of dimensions.
Here is an example of the code:
import random
import numpy as np
first_list = []
a = 0
while a <= 10:
first_list.append(a)
a += 1
random.shuffle(first_list)
second_list = []
b= 0
while b <= 10:
second_list.append(b)
b += 1
random.shuffle(second_list)
n = 0
xy_array = np.array([[first_list.index(n),second_list.index(n)]])
row_to_be_added =([[first_list.index(n+1),second_list.index(n+1)]])
while n<=len(first_list):
np.r_[xy_array,[row_to_be_added]]
n+=1
I get an error message that the dimensions are wrong. More specifically, I get the message "array at index 0 has 2 dimensions, but array at index 1 has 3 dimensions." I am trying to add additional rows to the matrix. What am I doing wrong?
Here is an example of the code:
import random
import numpy as np
first_list = []
a = 0
while a <= 10:
first_list.append(a)
a += 1
random.shuffle(first_list)
second_list = []
b= 0
while b <= 10:
second_list.append(b)
b += 1
random.shuffle(second_list)
n = 0
xy_array = np.array([[first_list.index(n),second_list.index(n)]])
row_to_be_added =([[first_list.index(n+1),second_list.index(n+1)]])
while n<=len(first_list):
np.r_[xy_array,[row_to_be_added]]
n+=1
I get an error message that the dimensions are wrong. More specifically, I get the message "array at index 0 has 2 dimensions, but array at index 1 has 3 dimensions." I am trying to add additional rows to the matrix. What am I doing wrong?
Last edited: