numpy 3-使用Python的维数据集

ryhaxcpt  于 2023-04-21  发布在  Python
关注(0)|答案(1)|浏览(102)

我正在尝试用Python编写这个参数的数据集。我使用了xarray,但我无法获得正确的代码...我如何用Python编写这个数据集?
我在下面写了一个参数的集合和数据集。

Sets
i "products" /i1, i2, i3, i4, i5, i6, i7, i8, i9, i10/
j "processing units" /j1, j2,  j3/
s "production sites" /s1, s2, s3/;

Table v(i,j,s)
          s1       s2       s3      
i1.j1     5                 
i2.j1     5        
i3.j1     5        
i4.j1     5        
i5.j2              6
i6.j2              6
i7.j2              6
i8.j2              6
i9.j3                        4
i10.j3                       4
;

如何在Python中编写此数据集?

isr3a4wc

isr3a4wc1#

首先,你给出的例子并不容易理解,但是我试着写了一些有用的东西。你可以使用np.meshgrid:

i = ["i1", "i2", "i3", "i4", "i5", "i6", "i7", "i8", "i9", "i10"]
j = ["j1", "j2",  "j3"]
s = ["s1", "s2", "s3"]
grid3d_i, grid3d_j, grid3d_s = np.meshgrid(i, j, s, indexing='ij')
# then you can print one print one point in 3d data like this:
grid3d_i[0][0][0], grid3d_j[0][0][0], grid3d_s[0][0][0]

相关问题