Numpy 2d array extrude
up vote
0
down vote
favorite
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.
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.
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.
What would be the best way to achive this? Endpoint of that task is to output this matrix into csv file.
Data schema:

python arrays numpy multidimensional-array
add a comment |
up vote
0
down vote
favorite
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.
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.
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.
What would be the best way to achive this? Endpoint of that task is to output this matrix into csv file.
Data schema:

python arrays numpy multidimensional-array
6
I think it might be better if you give an example with some sample data. Right now it is not completely clear what you aim to do.
– Willem Van Onsem
Nov 10 at 12:49
Added picture representing my issue in EDIT
– takeshi6
Nov 10 at 13:02
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
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.
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.
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.
What would be the best way to achive this? Endpoint of that task is to output this matrix into csv file.
Data schema:

python arrays numpy multidimensional-array
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.
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.
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.
What would be the best way to achive this? Endpoint of that task is to output this matrix into csv file.
Data schema:

python arrays numpy multidimensional-array
python arrays numpy multidimensional-array
edited Nov 10 at 13:12
asked Nov 10 at 12:47
takeshi6
113
113
6
I think it might be better if you give an example with some sample data. Right now it is not completely clear what you aim to do.
– Willem Van Onsem
Nov 10 at 12:49
Added picture representing my issue in EDIT
– takeshi6
Nov 10 at 13:02
add a comment |
6
I think it might be better if you give an example with some sample data. Right now it is not completely clear what you aim to do.
– Willem Van Onsem
Nov 10 at 12:49
Added picture representing my issue in EDIT
– takeshi6
Nov 10 at 13:02
6
6
I think it might be better if you give an example with some sample data. Right now it is not completely clear what you aim to do.
– Willem Van Onsem
Nov 10 at 12:49
I think it might be better if you give an example with some sample data. Right now it is not completely clear what you aim to do.
– Willem Van Onsem
Nov 10 at 12:49
Added picture representing my issue in EDIT
– takeshi6
Nov 10 at 13:02
Added picture representing my issue in EDIT
– takeshi6
Nov 10 at 13:02
add a comment |
3 Answers
3
active
oldest
votes
up vote
0
down vote
accepted
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']
Thanks for that advice, it seems to work. Guess i just i got confused that using np.ndarrays in my previous calculations means i have to use it till the very end)
– takeshi6
Nov 10 at 18:18
add a comment |
up vote
0
down vote
You may use np.append method in numpy.
You can check the details in numpy.append
I need to insert at certain index, not at the end
– takeshi6
Nov 10 at 13:04
I see. Then you can try a 3-d dataframe. But it's not recommended.
– DwayneChen
Nov 10 at 13:42
add a comment |
up vote
0
down vote
I think you could do this pretty cleanly with a dictionary like so:
file_pairs_table = {}
file_a = "file_a.txt"
file_b = "file_b.txt"
file_pairs_table[(file_a,file_b)] = np.arange(999) #operation resulting in 1d array here.
Then access the value of the file pair like this:
file_pairs_table[(file_a,file_b)]
>>> array([0,1,...,998])
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53239103%2fnumpy-2d-array-extrude%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
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']
Thanks for that advice, it seems to work. Guess i just i got confused that using np.ndarrays in my previous calculations means i have to use it till the very end)
– takeshi6
Nov 10 at 18:18
add a comment |
up vote
0
down vote
accepted
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']
Thanks for that advice, it seems to work. Guess i just i got confused that using np.ndarrays in my previous calculations means i have to use it till the very end)
– takeshi6
Nov 10 at 18:18
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
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']
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']
edited Nov 10 at 14:34
answered Nov 10 at 14:29
iGian
2,9622622
2,9622622
Thanks for that advice, it seems to work. Guess i just i got confused that using np.ndarrays in my previous calculations means i have to use it till the very end)
– takeshi6
Nov 10 at 18:18
add a comment |
Thanks for that advice, it seems to work. Guess i just i got confused that using np.ndarrays in my previous calculations means i have to use it till the very end)
– takeshi6
Nov 10 at 18:18
Thanks for that advice, it seems to work. Guess i just i got confused that using np.ndarrays in my previous calculations means i have to use it till the very end)
– takeshi6
Nov 10 at 18:18
Thanks for that advice, it seems to work. Guess i just i got confused that using np.ndarrays in my previous calculations means i have to use it till the very end)
– takeshi6
Nov 10 at 18:18
add a comment |
up vote
0
down vote
You may use np.append method in numpy.
You can check the details in numpy.append
I need to insert at certain index, not at the end
– takeshi6
Nov 10 at 13:04
I see. Then you can try a 3-d dataframe. But it's not recommended.
– DwayneChen
Nov 10 at 13:42
add a comment |
up vote
0
down vote
You may use np.append method in numpy.
You can check the details in numpy.append
I need to insert at certain index, not at the end
– takeshi6
Nov 10 at 13:04
I see. Then you can try a 3-d dataframe. But it's not recommended.
– DwayneChen
Nov 10 at 13:42
add a comment |
up vote
0
down vote
up vote
0
down vote
You may use np.append method in numpy.
You can check the details in numpy.append
You may use np.append method in numpy.
You can check the details in numpy.append
answered Nov 10 at 12:54
DwayneChen
11
11
I need to insert at certain index, not at the end
– takeshi6
Nov 10 at 13:04
I see. Then you can try a 3-d dataframe. But it's not recommended.
– DwayneChen
Nov 10 at 13:42
add a comment |
I need to insert at certain index, not at the end
– takeshi6
Nov 10 at 13:04
I see. Then you can try a 3-d dataframe. But it's not recommended.
– DwayneChen
Nov 10 at 13:42
I need to insert at certain index, not at the end
– takeshi6
Nov 10 at 13:04
I need to insert at certain index, not at the end
– takeshi6
Nov 10 at 13:04
I see. Then you can try a 3-d dataframe. But it's not recommended.
– DwayneChen
Nov 10 at 13:42
I see. Then you can try a 3-d dataframe. But it's not recommended.
– DwayneChen
Nov 10 at 13:42
add a comment |
up vote
0
down vote
I think you could do this pretty cleanly with a dictionary like so:
file_pairs_table = {}
file_a = "file_a.txt"
file_b = "file_b.txt"
file_pairs_table[(file_a,file_b)] = np.arange(999) #operation resulting in 1d array here.
Then access the value of the file pair like this:
file_pairs_table[(file_a,file_b)]
>>> array([0,1,...,998])
add a comment |
up vote
0
down vote
I think you could do this pretty cleanly with a dictionary like so:
file_pairs_table = {}
file_a = "file_a.txt"
file_b = "file_b.txt"
file_pairs_table[(file_a,file_b)] = np.arange(999) #operation resulting in 1d array here.
Then access the value of the file pair like this:
file_pairs_table[(file_a,file_b)]
>>> array([0,1,...,998])
add a comment |
up vote
0
down vote
up vote
0
down vote
I think you could do this pretty cleanly with a dictionary like so:
file_pairs_table = {}
file_a = "file_a.txt"
file_b = "file_b.txt"
file_pairs_table[(file_a,file_b)] = np.arange(999) #operation resulting in 1d array here.
Then access the value of the file pair like this:
file_pairs_table[(file_a,file_b)]
>>> array([0,1,...,998])
I think you could do this pretty cleanly with a dictionary like so:
file_pairs_table = {}
file_a = "file_a.txt"
file_b = "file_b.txt"
file_pairs_table[(file_a,file_b)] = np.arange(999) #operation resulting in 1d array here.
Then access the value of the file pair like this:
file_pairs_table[(file_a,file_b)]
>>> array([0,1,...,998])
answered Nov 10 at 22:57
Doug7
212
212
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53239103%2fnumpy-2d-array-extrude%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
6
I think it might be better if you give an example with some sample data. Right now it is not completely clear what you aim to do.
– Willem Van Onsem
Nov 10 at 12:49
Added picture representing my issue in EDIT
– takeshi6
Nov 10 at 13:02