Numpy 2D阵列拉伸 [英] Numpy 2d array extrude
问题描述
我是numpy ndarrays的新手,我找不到解决我问题的方法. 我说过10个浮点数据文件.我对每对文件执行一些操作,返回一维数组.
I am new to numpy ndarrays and i couldn`t find any solution for my issue. I have say 10 files of floating point data. I apply some operation for every pair of files, that returns 1D array.
我想要的是让具有行和列的块矩阵A [10x10]是我的十个文件,并且该矩阵中的每个元素都是一维数组的块,这导致将我的操作应用于f_i和f_j.
What I want is to have block matrix A[10x10] with rows and cols are my ten files and every element in that matrix is block of 1D array that results my operation applied to f_i and f_j.
我猜我需要某种类型的地图,以便我可以告诉此f_i和f_j结果在特定数组中",并可以通过f_i,f_j访问此数组.
I gues i need some kind of map, so that i could tell "This f_i and f_j result in certain array" and could access this array by f_i, f_j.
实现这一目标的最佳方法是什么?该任务的终点是将该矩阵输出到csv文件中.
What would be the best way to achive this? Endpoint of that task is to output this matrix into csv file.
数据模式:
推荐答案
Maybe you can accomplish your goal just using a nested list (https://docs.python.org/3.7/tutorial/datastructures.html#nested-list-comprehensions):
# build a 10x10 matrix with default value 0
matrix = [[0 for i in range(10)] for j in range(10)]
# assign the result to a cell
matrix[1][1] = ['result', 'of', 'some', 'operation']
# retrieve the result
print (matrix[1][1])
#=> ['result', 'of', 'some', 'operation']
这篇关于Numpy 2D阵列拉伸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!