You’ll want to store the whole matrix in st.session_state and access the whole thing in turn.
if 'my_matrix' not in st.session_state:
st.session_state.my_matrix = [[0]*10 for i in range(10)]
# Access and work with your matrix, for example
st.session_state.my_matrix[2][3] = 4
That was my bad in copying down what I meant. I’ve corrected it. The line inside the conditional was meant to initialize the key/value pair so that it could then be called upon.
if 'my_matrix' not in st.session_state:
st.session_state.my_matrix = [[0]*10 for i in range(10)]
# Access and work with your matrix, for example
st.session_state.my_matrix[2][3] = 4
@blob123 It seems like perhaps you’re overwriting st.session_state itself with a list, something like this perhaps:
st.session_state = [...]
Are you doing that somewhere in your script? If not, can you share a complete minimal script which reproduces that error message?
For example, this works fine:
import streamlit as st
if "my_matrix" not in st.session_state:
st.session_state.my_matrix = [[0] * 10 for i in range(10)]
# Access and work with your matrix, for example
st.session_state.my_matrix[2][3] = 4
st.write(st.session_state)