[PYTHON] When creating a matrix in a list

Notes for yourself

Suppose you generate a list that has a 3x3 zero matrix as each element of the list as shown below.

A=[np.zeros((3,3))]*(3)


 Consider assigning a value to this list

In : A Out: [array([[ 0., 0., 0.], [ 0., 0., 0.], [ 0., 0., 0.]]), array([[ 0., 0., 0.], [ 0., 0., 0.], [ 0., 0., 0.]]), array([[ 0., 0., 0.], [ 0., 0., 0.], [ 0., 0., 0.]])]


 Here, substitute the value in the first row of the first element (zero matrix) as shown below.


A[0][0]=1



 After performing this operation, A becomes as follows.

In : A Out: [array([[ 1., 1., 1.], [ 0., 0., 0.], [ 0., 0., 0.]]), array([[ 1., 1., 1.], [ 0., 0., 0.], [ 0., 0., 0.]]), array([[ 1., 1., 1.], [ 0., 0., 0.], [ 0., 0., 0.]])]


 Assigned to all elements! ??
 Let's be careful……
 (Gentlely ``` np.zeros ((3,3,3)) I wonder if it should have been generated with` ``
 How smart is it when you want to create a multidimensional matrix with different numbers of elements for each element (I don't know if this kind of expression is allowed).


Recommended Posts

When creating a matrix in a list
Things to note when initializing a list in Python
Creating a list when the nomenclature is a fixed time
[python] Manage functions in a list
Draw a scatterplot matrix in python
Behavior when giving a list with shell = True in subprocess
A memo when creating a directed graph using Graphviz in Python
Precautions when creating a Python generator
When writing a program in Python
Precautions when pickling a function in python
Display a list of alphabets in Python 3
Change the list in a for statement
Creating a virtual environment in an Anaconda environment
[Python memo] Be careful when creating a two-dimensional array (list of lists)
What to do when a warning message is displayed in pip list
When I get a chromedriver error in Selenium
How to clear tuples in a list (Python)
Ubuntu18.04.05 Creating a python virtual environment in LTS
Make a copy of the list in Python
Get only the subclass elements in a list
View drug reviews using a list in Python
A memo when creating a python environment with miniconda
[Python] Find the transposed matrix in a comprehension
Sort list elements in a specified order in Python
[Python] Manipulating elements in a list (array) [Sort]
What I was addicted to when creating a web application in a windows environment
Sorted list in Python
FizzBuzz in list comprehension
[Day 9] Creating a model
A list of stumbling blocks in Django's image upload
Creating a Home screen
I get a java.util.regex.PatternSyntaxException when splitting a string in PySpark
4. Creating a structured program
Differences in behavior between append () and "+ =" operators when adding data to a list in Python
Be careful when differentiating the eigenvectors of a matrix
Filter List in Python
A memorandum when writing experimental code ~ Logging in python
Problems when creating a csv-json conversion tool with python
Make a distance matrix
dict in dict Makes a dict a dict
Creating a scraping tool
What's in that variable (when running a Python script)
Use communicate () when receiving output in a Python subprocess
Group by consecutive elements of a list in Python
Stumble when converting bidirectional list to JSON in Go
When you want to plt.save in a for statement
Current directory when creating a new one with Jupyter
When I got a list of study sessions in Python, I found something I wanted to make
A shell script that numbers duplicate names when creating files
Try creating a Deep Zoom file format .DZI in Python
Create a list in Python with all followers on twitter
100 Language Processing Knock-84 (using pandas): Creating a word context matrix
Get the number of specific elements in a python list
A story that stumbled when using pip in a proxy environment
Opens in a new window when launching Jupyter Notebook (Windows)
Developed a library to get Kindle collection list in Python
Convenient writing method when appending to list continuously in Python
How to get the last (last) value in a list in Python
Create a new list by combining duplicate elements in the list
Find the eigenvalues of a real symmetric matrix in Python
Automatically opens in a new window when launching Jupyter Notebook