python-3.x 我想改变从垂直输入到列输入使用streamlit也,列必须是动态的

gojuced7  于 2023-03-24  发布在  Python
关注(0)|答案(1)|浏览(113)
import numpy as np
import streamlit as st

st.header('Input Data')
p = np.array([[4,3,6,2],[1,4,3,5],[2,5,2,3],[5,2,4,1],[3,6,1,4]])
st.dataframe(p)
t = []
tb = len(p)
st.subheader('Enter the T value into row for multiplication')
for i in range(tb):
  value = st.number_input(f'row{i}:', min_value=0, max_value=10, step=1)
  t.append(value)
t = np.array(t)
t = np.tile(t, (p.shape[1], 1)).T 
p_mod = np.multiply(p, t)

st.header('Output Data')
st.dataframe(p_mod)

假设如果我运行上面的代码,我会得到垂直顺序的数字输入,但我想有水平顺序

2izufjch

2izufjch1#

我想你要找的是st.columns
也许试试

c = st.columns(tb)
for i in range(tb):
  value = c[i].number_input(f'row{i}:', min_value=0, max_value=10, step=1)
  t.append(value)

相关问题