Adding a 2D array does not work as expected.
The environment is
a =  b =  for i in range (1,11): a.append (i) if i% 5 = 0: Print (a) # 1st time: a = [1,2,3,4,5] # 2: a = [6,7,8,9,10] b. append (a) Print (b) # 1st time: b = [[1,2,3,4,5]] # 2nd time: b = [[6,7,8,9,10], [6,7,8,9,10]] a.clear () print (b) #b = [, ]
As mentioned above, the list added first will be overwritten and added.
Moreover, it becomes empty when the for statement is exited.
Please write the result of trying in your environment or the solution.
The assumption is
b = [[1,2,3,4,5], [6,7,8,9,10]]
Is it due to the version?
Answer # 1
A story addicted to copying the list I think that will be helpful.
The following is an example of countermeasures
a =  b =  for i in range (1,11): a.append (i) if i% 5 == 0: b.append (a [:]) a.clear () print (b) # [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]]
Although it is a snake, it is convenient to use numpy etc. for array operation.
import numpy as np a = np.array (range (1,11)) b = a.reshape ([-1,5]) print (b) # [[1 2 3 4 5] # [6 7 8 9 10]]
Answer # 2
The question code contains double-byte spaces,
It cannot be executed because == becomes =.
Copy and paste the code that is working.
a = It would be good to set it to.
Do you know why?
- how to use python 2d array
- python - about replacement of data in two-dimensional array
- python - how to sort a 3d array
- python hdf5 how to add to saved data (how to use mode ='a')
- python - i want to extract only specific rows in a two-dimensional array
- python - convert a one-dimensional array to a two-dimensional array
- python - how to display how many multiples of 7 are
- python - i don't know how to use wait_for_motion () and wait_for_no_motion ()
- python - how to delete an apostrophe in the list
- python - handling of 1d array data when using the predict function in keras
- python - i don't know how to do css select in bs4
- python - i want to add an element to a double list
- python - i want to swap the first half and the second half of the array and put them in different arrays
- if you put values in a two-dimensional array of c ++ structures and sort them in ascending order, the values will be 0
- php - how to make an array of js into json, post and receive
- python - how to use tensorflow placeholder
- python 3x - about assigning python to a two-dimensional list
- python - i don't know how to deal with the error
- python - how to get alphabets in order with for in
- python 3x - i want to run anaconda3 python from visual studio code it may or may not move
- (django) i can't post with images
- windows - i want to change theano of using theano backend to tensorflow
- python 3x - i learned my own data with yolo-v3, but the recognition result is the same as before my own learning
- python - i want to divide the image into grids and find the hsv value
- python - i want to combine split images
- python - i am in trouble because the cause of invalid syntax is unknown
- python - i am in trouble because the cause of attributeerror is unknown
- about reading files
- python 3x - xg boost cannot be installed from anaconda prompt