How to combine 2 ndarrays with different dimensions?How to merge two dictionaries in a single expression?How do I check if a list is empty?How do I check whether a file exists without exceptions?What is the difference between @staticmethod and @classmethod?What is the difference between Python's list methods append and extend?How can I safely create a nested directory?How do I sort a dictionary by value?How to make a chain of function decorators?Difference between __str__ and __repr__?How do I list all files of a directory?

Accent on í misaligned in bibliography / citation

Can realistic planetary invasion have any meaningful strategy?

Dealing with an extrovert co-worker

What is the history of the university asylum law?

How to use "Du hast/ Du hattest'?

Do AT motherboards (286, 386, 486) really need -5V (besides redirecting it to ISA connectors)?

Why don't electrons take the shorter path in coils?

How do I request a longer than normal leave of absence period for my wedding?

In the MCU, why does Mjölnir retain its enchantments after Ragnarok?

Is “I am getting married with my sister” ambiguous?

Start from ones

Avoiding racist tropes in fantasy

See details of old sessions

Mathematical uses of string theory

How much code would a codegolf golf if a codegolf could golf code?

Fried gnocchi with spinach, bacon, cream sauce in a single pan

Why in most German places is the church the tallest building?

Does norwegian.no airline overbook flights?

Using `With[...]` with a list specification as a variable

Sun setting in East!

Are there account age or level requirements for obtaining special research?

Which household object drew this pattern?

Are there any music source codes for sound chips?

In an emergency, how do I find and share my position?



How to combine 2 ndarrays with different dimensions?


How to merge two dictionaries in a single expression?How do I check if a list is empty?How do I check whether a file exists without exceptions?What is the difference between @staticmethod and @classmethod?What is the difference between Python's list methods append and extend?How can I safely create a nested directory?How do I sort a dictionary by value?How to make a chain of function decorators?Difference between __str__ and __repr__?How do I list all files of a directory?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I have a (123, 3072) array and i need to split it to 5 approximately same folds (approximately, because 123 can't be divided by 5, for example) in order to do a 5-fold cross-validation. scikit-learn is not allowed. I tried to get 2 ndarrays of size (3, 25, 3072) and (2, 24, 3072). Now i need to combine them, but every function i try raises this:



ValueError: all the input array dimensions except for the concatenation 
axis must match exactly


Is it possible to concatenate them?



This is my code:



num_folds = 5
mod = binary_train_X.shape[0] % num_folds
first_records = (binary_train_X.shape[0] - mod) // num_folds + 1
last_records = first_records - 1
first_part = binary_train_X[:mod * first_records].reshape([mod, first_records, -1])
second_part = binary_train_X[mod * first_records:].reshape([num_folds - mod, last_records, -1])
folds_X = np.concatenate((first_part, second_part))


Or maybe there is another way to split it into 5 parts(folds)?










share|improve this question


























  • Is your question about how to combine these two arrays, or to do cross validation without sci-kit? I'm also a bit perplexed as to why you wanted, assuming its correct, to split a (123, 3072) array into a (3, 25, 3072) and a (2, 24, 3072) array (why make a 2d array into a 3d one? Also those numbers do not add up).

    – Evan Mata
    Mar 27 at 16:51











  • @EvanMata, my question is how to combine them. Or whether there is an another way to get 5 folds of training data of approximately same size. Because, 123, for example, can't be divided by 5.

    – Никита Бабенко
    Mar 27 at 16:55











  • You could reshape the arrays to 2d, (75,3072) and ((48,3072), and then concatenate on axis 0. The numbers add up to 123.

    – hpaulj
    Mar 27 at 16:55











  • @hpaulj, so we get an array (123, 3072), which we had in the beginning?

    – Никита Бабенко
    Mar 27 at 16:59











  • Yes, we would. Isn't that what you want? That's the only combination that makes sense to me. Do you have something else in mind?

    – hpaulj
    Mar 27 at 17:34

















0















I have a (123, 3072) array and i need to split it to 5 approximately same folds (approximately, because 123 can't be divided by 5, for example) in order to do a 5-fold cross-validation. scikit-learn is not allowed. I tried to get 2 ndarrays of size (3, 25, 3072) and (2, 24, 3072). Now i need to combine them, but every function i try raises this:



ValueError: all the input array dimensions except for the concatenation 
axis must match exactly


Is it possible to concatenate them?



This is my code:



num_folds = 5
mod = binary_train_X.shape[0] % num_folds
first_records = (binary_train_X.shape[0] - mod) // num_folds + 1
last_records = first_records - 1
first_part = binary_train_X[:mod * first_records].reshape([mod, first_records, -1])
second_part = binary_train_X[mod * first_records:].reshape([num_folds - mod, last_records, -1])
folds_X = np.concatenate((first_part, second_part))


Or maybe there is another way to split it into 5 parts(folds)?










share|improve this question


























  • Is your question about how to combine these two arrays, or to do cross validation without sci-kit? I'm also a bit perplexed as to why you wanted, assuming its correct, to split a (123, 3072) array into a (3, 25, 3072) and a (2, 24, 3072) array (why make a 2d array into a 3d one? Also those numbers do not add up).

    – Evan Mata
    Mar 27 at 16:51











  • @EvanMata, my question is how to combine them. Or whether there is an another way to get 5 folds of training data of approximately same size. Because, 123, for example, can't be divided by 5.

    – Никита Бабенко
    Mar 27 at 16:55











  • You could reshape the arrays to 2d, (75,3072) and ((48,3072), and then concatenate on axis 0. The numbers add up to 123.

    – hpaulj
    Mar 27 at 16:55











  • @hpaulj, so we get an array (123, 3072), which we had in the beginning?

    – Никита Бабенко
    Mar 27 at 16:59











  • Yes, we would. Isn't that what you want? That's the only combination that makes sense to me. Do you have something else in mind?

    – hpaulj
    Mar 27 at 17:34













0












0








0








I have a (123, 3072) array and i need to split it to 5 approximately same folds (approximately, because 123 can't be divided by 5, for example) in order to do a 5-fold cross-validation. scikit-learn is not allowed. I tried to get 2 ndarrays of size (3, 25, 3072) and (2, 24, 3072). Now i need to combine them, but every function i try raises this:



ValueError: all the input array dimensions except for the concatenation 
axis must match exactly


Is it possible to concatenate them?



This is my code:



num_folds = 5
mod = binary_train_X.shape[0] % num_folds
first_records = (binary_train_X.shape[0] - mod) // num_folds + 1
last_records = first_records - 1
first_part = binary_train_X[:mod * first_records].reshape([mod, first_records, -1])
second_part = binary_train_X[mod * first_records:].reshape([num_folds - mod, last_records, -1])
folds_X = np.concatenate((first_part, second_part))


Or maybe there is another way to split it into 5 parts(folds)?










share|improve this question
















I have a (123, 3072) array and i need to split it to 5 approximately same folds (approximately, because 123 can't be divided by 5, for example) in order to do a 5-fold cross-validation. scikit-learn is not allowed. I tried to get 2 ndarrays of size (3, 25, 3072) and (2, 24, 3072). Now i need to combine them, but every function i try raises this:



ValueError: all the input array dimensions except for the concatenation 
axis must match exactly


Is it possible to concatenate them?



This is my code:



num_folds = 5
mod = binary_train_X.shape[0] % num_folds
first_records = (binary_train_X.shape[0] - mod) // num_folds + 1
last_records = first_records - 1
first_part = binary_train_X[:mod * first_records].reshape([mod, first_records, -1])
second_part = binary_train_X[mod * first_records:].reshape([num_folds - mod, last_records, -1])
folds_X = np.concatenate((first_part, second_part))


Or maybe there is another way to split it into 5 parts(folds)?







python numpy






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 27 at 17:56







Никита Бабенко

















asked Mar 27 at 16:47









Никита БабенкоНикита Бабенко

256 bronze badges




256 bronze badges















  • Is your question about how to combine these two arrays, or to do cross validation without sci-kit? I'm also a bit perplexed as to why you wanted, assuming its correct, to split a (123, 3072) array into a (3, 25, 3072) and a (2, 24, 3072) array (why make a 2d array into a 3d one? Also those numbers do not add up).

    – Evan Mata
    Mar 27 at 16:51











  • @EvanMata, my question is how to combine them. Or whether there is an another way to get 5 folds of training data of approximately same size. Because, 123, for example, can't be divided by 5.

    – Никита Бабенко
    Mar 27 at 16:55











  • You could reshape the arrays to 2d, (75,3072) and ((48,3072), and then concatenate on axis 0. The numbers add up to 123.

    – hpaulj
    Mar 27 at 16:55











  • @hpaulj, so we get an array (123, 3072), which we had in the beginning?

    – Никита Бабенко
    Mar 27 at 16:59











  • Yes, we would. Isn't that what you want? That's the only combination that makes sense to me. Do you have something else in mind?

    – hpaulj
    Mar 27 at 17:34

















  • Is your question about how to combine these two arrays, or to do cross validation without sci-kit? I'm also a bit perplexed as to why you wanted, assuming its correct, to split a (123, 3072) array into a (3, 25, 3072) and a (2, 24, 3072) array (why make a 2d array into a 3d one? Also those numbers do not add up).

    – Evan Mata
    Mar 27 at 16:51











  • @EvanMata, my question is how to combine them. Or whether there is an another way to get 5 folds of training data of approximately same size. Because, 123, for example, can't be divided by 5.

    – Никита Бабенко
    Mar 27 at 16:55











  • You could reshape the arrays to 2d, (75,3072) and ((48,3072), and then concatenate on axis 0. The numbers add up to 123.

    – hpaulj
    Mar 27 at 16:55











  • @hpaulj, so we get an array (123, 3072), which we had in the beginning?

    – Никита Бабенко
    Mar 27 at 16:59











  • Yes, we would. Isn't that what you want? That's the only combination that makes sense to me. Do you have something else in mind?

    – hpaulj
    Mar 27 at 17:34
















Is your question about how to combine these two arrays, or to do cross validation without sci-kit? I'm also a bit perplexed as to why you wanted, assuming its correct, to split a (123, 3072) array into a (3, 25, 3072) and a (2, 24, 3072) array (why make a 2d array into a 3d one? Also those numbers do not add up).

– Evan Mata
Mar 27 at 16:51





Is your question about how to combine these two arrays, or to do cross validation without sci-kit? I'm also a bit perplexed as to why you wanted, assuming its correct, to split a (123, 3072) array into a (3, 25, 3072) and a (2, 24, 3072) array (why make a 2d array into a 3d one? Also those numbers do not add up).

– Evan Mata
Mar 27 at 16:51













@EvanMata, my question is how to combine them. Or whether there is an another way to get 5 folds of training data of approximately same size. Because, 123, for example, can't be divided by 5.

– Никита Бабенко
Mar 27 at 16:55





@EvanMata, my question is how to combine them. Or whether there is an another way to get 5 folds of training data of approximately same size. Because, 123, for example, can't be divided by 5.

– Никита Бабенко
Mar 27 at 16:55













You could reshape the arrays to 2d, (75,3072) and ((48,3072), and then concatenate on axis 0. The numbers add up to 123.

– hpaulj
Mar 27 at 16:55





You could reshape the arrays to 2d, (75,3072) and ((48,3072), and then concatenate on axis 0. The numbers add up to 123.

– hpaulj
Mar 27 at 16:55













@hpaulj, so we get an array (123, 3072), which we had in the beginning?

– Никита Бабенко
Mar 27 at 16:59





@hpaulj, so we get an array (123, 3072), which we had in the beginning?

– Никита Бабенко
Mar 27 at 16:59













Yes, we would. Isn't that what you want? That's the only combination that makes sense to me. Do you have something else in mind?

– hpaulj
Mar 27 at 17:34





Yes, we would. Isn't that what you want? That's the only combination that makes sense to me. Do you have something else in mind?

– hpaulj
Mar 27 at 17:34












2 Answers
2






active

oldest

votes


















0















Something very similar to this, if not exactly this.



def k_fold(array, num_folds): #New to WOS
#Splits along axis 0 of array
folds = []
start = 0
step = array.shape[0]/num_folds
for i in range(num_folds):
end = int(start + step)
start = int(start)
fold = array[start:end]
rest_of_array = np.concatenate((array[:start],array[end:]), axis = 0)
start = end
folds.append((fold, rest_of_array))
return folds





share|improve this answer

























  • There might be some off-by-one errors, I didn't really both to check.

    – Evan Mata
    Mar 27 at 17:20











  • in this case we miss the last 3 arrays because 123 can't be divided by 5

    – Никита Бабенко
    Mar 27 at 17:30











  • Just do something after the for loop thats like remaining = array[end:] and then distributes the remaining. Alternatively, maybe try having end = rounded up start + step

    – Evan Mata
    Mar 27 at 17:36


















0
















Since 377856 (123*3072) is not divisible by 15360 (5*3072) (123 is not divisible by 5), it is only possible to create 5 equal slices of 3072 by either truncating or padding to a multiple of 15360 (5*3072).



Truncating creates shape (5, 24, 3072) by discarding values from the end until it aligns:



folds = binary_train_X.flatten()[:np.prod(binary_train_X.shape)//(5*3072)*(5*3072)].reshape(5, -1, 3072)
# this discards 9216 (3072*3) values


Padding creates shape (5, 25, 3072) by appending zeros to the end until it aligns:



folds = np.pad(binary_train_X.flatten(), (0, -(-np.prod(binary_train_X.shape)//(5*3072))*(5*3072)-np.prod(binary_train_X.shape)), 'constant').reshape(5, -1, 3072)
# this appends 6144 (3072*2) zeros





share|improve this answer



























  • If i do like this, i get a (123, 3072) array, which i had started with from the beginning. But i need to connect them by first coordinate somehow.

    – Никита Бабенко
    Mar 27 at 17:41











  • From your question, I assumed you wanted a 2D array, with the original dimensions. If my assessment is incorrect, please tell what shape you are looking for? What do you mean by "first coordinate"? Or is it the internal order within first_part and second_part that's important?

    – mossymountain
    Mar 27 at 17:48











  • i mean i managed to split the original array(binary_train_X) into 2 arrays: (3, 25, 3072) and (2, 24, 3072). I need to concatenate them somehow to get a one 3-dimensional array of size (5, *, 3072). Original idea is: I need to split binary_train_X to 5 approximately same folds (approximately, because 123 can't be divided by 5, for example) in order to do a 5-fold cross-validation. Thing described above is my vision of doing it. It may be wrong, that's why i need some advise.

    – Никита Бабенко
    Mar 27 at 17:53













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
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55382505%2fhow-to-combine-2-ndarrays-with-different-dimensions%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









0















Something very similar to this, if not exactly this.



def k_fold(array, num_folds): #New to WOS
#Splits along axis 0 of array
folds = []
start = 0
step = array.shape[0]/num_folds
for i in range(num_folds):
end = int(start + step)
start = int(start)
fold = array[start:end]
rest_of_array = np.concatenate((array[:start],array[end:]), axis = 0)
start = end
folds.append((fold, rest_of_array))
return folds





share|improve this answer

























  • There might be some off-by-one errors, I didn't really both to check.

    – Evan Mata
    Mar 27 at 17:20











  • in this case we miss the last 3 arrays because 123 can't be divided by 5

    – Никита Бабенко
    Mar 27 at 17:30











  • Just do something after the for loop thats like remaining = array[end:] and then distributes the remaining. Alternatively, maybe try having end = rounded up start + step

    – Evan Mata
    Mar 27 at 17:36















0















Something very similar to this, if not exactly this.



def k_fold(array, num_folds): #New to WOS
#Splits along axis 0 of array
folds = []
start = 0
step = array.shape[0]/num_folds
for i in range(num_folds):
end = int(start + step)
start = int(start)
fold = array[start:end]
rest_of_array = np.concatenate((array[:start],array[end:]), axis = 0)
start = end
folds.append((fold, rest_of_array))
return folds





share|improve this answer

























  • There might be some off-by-one errors, I didn't really both to check.

    – Evan Mata
    Mar 27 at 17:20











  • in this case we miss the last 3 arrays because 123 can't be divided by 5

    – Никита Бабенко
    Mar 27 at 17:30











  • Just do something after the for loop thats like remaining = array[end:] and then distributes the remaining. Alternatively, maybe try having end = rounded up start + step

    – Evan Mata
    Mar 27 at 17:36













0














0










0









Something very similar to this, if not exactly this.



def k_fold(array, num_folds): #New to WOS
#Splits along axis 0 of array
folds = []
start = 0
step = array.shape[0]/num_folds
for i in range(num_folds):
end = int(start + step)
start = int(start)
fold = array[start:end]
rest_of_array = np.concatenate((array[:start],array[end:]), axis = 0)
start = end
folds.append((fold, rest_of_array))
return folds





share|improve this answer













Something very similar to this, if not exactly this.



def k_fold(array, num_folds): #New to WOS
#Splits along axis 0 of array
folds = []
start = 0
step = array.shape[0]/num_folds
for i in range(num_folds):
end = int(start + step)
start = int(start)
fold = array[start:end]
rest_of_array = np.concatenate((array[:start],array[end:]), axis = 0)
start = end
folds.append((fold, rest_of_array))
return folds






share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 27 at 17:19









Evan MataEvan Mata

16713 bronze badges




16713 bronze badges















  • There might be some off-by-one errors, I didn't really both to check.

    – Evan Mata
    Mar 27 at 17:20











  • in this case we miss the last 3 arrays because 123 can't be divided by 5

    – Никита Бабенко
    Mar 27 at 17:30











  • Just do something after the for loop thats like remaining = array[end:] and then distributes the remaining. Alternatively, maybe try having end = rounded up start + step

    – Evan Mata
    Mar 27 at 17:36

















  • There might be some off-by-one errors, I didn't really both to check.

    – Evan Mata
    Mar 27 at 17:20











  • in this case we miss the last 3 arrays because 123 can't be divided by 5

    – Никита Бабенко
    Mar 27 at 17:30











  • Just do something after the for loop thats like remaining = array[end:] and then distributes the remaining. Alternatively, maybe try having end = rounded up start + step

    – Evan Mata
    Mar 27 at 17:36
















There might be some off-by-one errors, I didn't really both to check.

– Evan Mata
Mar 27 at 17:20





There might be some off-by-one errors, I didn't really both to check.

– Evan Mata
Mar 27 at 17:20













in this case we miss the last 3 arrays because 123 can't be divided by 5

– Никита Бабенко
Mar 27 at 17:30





in this case we miss the last 3 arrays because 123 can't be divided by 5

– Никита Бабенко
Mar 27 at 17:30













Just do something after the for loop thats like remaining = array[end:] and then distributes the remaining. Alternatively, maybe try having end = rounded up start + step

– Evan Mata
Mar 27 at 17:36





Just do something after the for loop thats like remaining = array[end:] and then distributes the remaining. Alternatively, maybe try having end = rounded up start + step

– Evan Mata
Mar 27 at 17:36













0
















Since 377856 (123*3072) is not divisible by 15360 (5*3072) (123 is not divisible by 5), it is only possible to create 5 equal slices of 3072 by either truncating or padding to a multiple of 15360 (5*3072).



Truncating creates shape (5, 24, 3072) by discarding values from the end until it aligns:



folds = binary_train_X.flatten()[:np.prod(binary_train_X.shape)//(5*3072)*(5*3072)].reshape(5, -1, 3072)
# this discards 9216 (3072*3) values


Padding creates shape (5, 25, 3072) by appending zeros to the end until it aligns:



folds = np.pad(binary_train_X.flatten(), (0, -(-np.prod(binary_train_X.shape)//(5*3072))*(5*3072)-np.prod(binary_train_X.shape)), 'constant').reshape(5, -1, 3072)
# this appends 6144 (3072*2) zeros





share|improve this answer



























  • If i do like this, i get a (123, 3072) array, which i had started with from the beginning. But i need to connect them by first coordinate somehow.

    – Никита Бабенко
    Mar 27 at 17:41











  • From your question, I assumed you wanted a 2D array, with the original dimensions. If my assessment is incorrect, please tell what shape you are looking for? What do you mean by "first coordinate"? Or is it the internal order within first_part and second_part that's important?

    – mossymountain
    Mar 27 at 17:48











  • i mean i managed to split the original array(binary_train_X) into 2 arrays: (3, 25, 3072) and (2, 24, 3072). I need to concatenate them somehow to get a one 3-dimensional array of size (5, *, 3072). Original idea is: I need to split binary_train_X to 5 approximately same folds (approximately, because 123 can't be divided by 5, for example) in order to do a 5-fold cross-validation. Thing described above is my vision of doing it. It may be wrong, that's why i need some advise.

    – Никита Бабенко
    Mar 27 at 17:53















0
















Since 377856 (123*3072) is not divisible by 15360 (5*3072) (123 is not divisible by 5), it is only possible to create 5 equal slices of 3072 by either truncating or padding to a multiple of 15360 (5*3072).



Truncating creates shape (5, 24, 3072) by discarding values from the end until it aligns:



folds = binary_train_X.flatten()[:np.prod(binary_train_X.shape)//(5*3072)*(5*3072)].reshape(5, -1, 3072)
# this discards 9216 (3072*3) values


Padding creates shape (5, 25, 3072) by appending zeros to the end until it aligns:



folds = np.pad(binary_train_X.flatten(), (0, -(-np.prod(binary_train_X.shape)//(5*3072))*(5*3072)-np.prod(binary_train_X.shape)), 'constant').reshape(5, -1, 3072)
# this appends 6144 (3072*2) zeros





share|improve this answer



























  • If i do like this, i get a (123, 3072) array, which i had started with from the beginning. But i need to connect them by first coordinate somehow.

    – Никита Бабенко
    Mar 27 at 17:41











  • From your question, I assumed you wanted a 2D array, with the original dimensions. If my assessment is incorrect, please tell what shape you are looking for? What do you mean by "first coordinate"? Or is it the internal order within first_part and second_part that's important?

    – mossymountain
    Mar 27 at 17:48











  • i mean i managed to split the original array(binary_train_X) into 2 arrays: (3, 25, 3072) and (2, 24, 3072). I need to concatenate them somehow to get a one 3-dimensional array of size (5, *, 3072). Original idea is: I need to split binary_train_X to 5 approximately same folds (approximately, because 123 can't be divided by 5, for example) in order to do a 5-fold cross-validation. Thing described above is my vision of doing it. It may be wrong, that's why i need some advise.

    – Никита Бабенко
    Mar 27 at 17:53













0














0










0










Since 377856 (123*3072) is not divisible by 15360 (5*3072) (123 is not divisible by 5), it is only possible to create 5 equal slices of 3072 by either truncating or padding to a multiple of 15360 (5*3072).



Truncating creates shape (5, 24, 3072) by discarding values from the end until it aligns:



folds = binary_train_X.flatten()[:np.prod(binary_train_X.shape)//(5*3072)*(5*3072)].reshape(5, -1, 3072)
# this discards 9216 (3072*3) values


Padding creates shape (5, 25, 3072) by appending zeros to the end until it aligns:



folds = np.pad(binary_train_X.flatten(), (0, -(-np.prod(binary_train_X.shape)//(5*3072))*(5*3072)-np.prod(binary_train_X.shape)), 'constant').reshape(5, -1, 3072)
# this appends 6144 (3072*2) zeros





share|improve this answer
















Since 377856 (123*3072) is not divisible by 15360 (5*3072) (123 is not divisible by 5), it is only possible to create 5 equal slices of 3072 by either truncating or padding to a multiple of 15360 (5*3072).



Truncating creates shape (5, 24, 3072) by discarding values from the end until it aligns:



folds = binary_train_X.flatten()[:np.prod(binary_train_X.shape)//(5*3072)*(5*3072)].reshape(5, -1, 3072)
# this discards 9216 (3072*3) values


Padding creates shape (5, 25, 3072) by appending zeros to the end until it aligns:



folds = np.pad(binary_train_X.flatten(), (0, -(-np.prod(binary_train_X.shape)//(5*3072))*(5*3072)-np.prod(binary_train_X.shape)), 'constant').reshape(5, -1, 3072)
# this appends 6144 (3072*2) zeros






share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 27 at 19:06

























answered Mar 27 at 17:27









mossymountainmossymountain

1036 bronze badges




1036 bronze badges















  • If i do like this, i get a (123, 3072) array, which i had started with from the beginning. But i need to connect them by first coordinate somehow.

    – Никита Бабенко
    Mar 27 at 17:41











  • From your question, I assumed you wanted a 2D array, with the original dimensions. If my assessment is incorrect, please tell what shape you are looking for? What do you mean by "first coordinate"? Or is it the internal order within first_part and second_part that's important?

    – mossymountain
    Mar 27 at 17:48











  • i mean i managed to split the original array(binary_train_X) into 2 arrays: (3, 25, 3072) and (2, 24, 3072). I need to concatenate them somehow to get a one 3-dimensional array of size (5, *, 3072). Original idea is: I need to split binary_train_X to 5 approximately same folds (approximately, because 123 can't be divided by 5, for example) in order to do a 5-fold cross-validation. Thing described above is my vision of doing it. It may be wrong, that's why i need some advise.

    – Никита Бабенко
    Mar 27 at 17:53

















  • If i do like this, i get a (123, 3072) array, which i had started with from the beginning. But i need to connect them by first coordinate somehow.

    – Никита Бабенко
    Mar 27 at 17:41











  • From your question, I assumed you wanted a 2D array, with the original dimensions. If my assessment is incorrect, please tell what shape you are looking for? What do you mean by "first coordinate"? Or is it the internal order within first_part and second_part that's important?

    – mossymountain
    Mar 27 at 17:48











  • i mean i managed to split the original array(binary_train_X) into 2 arrays: (3, 25, 3072) and (2, 24, 3072). I need to concatenate them somehow to get a one 3-dimensional array of size (5, *, 3072). Original idea is: I need to split binary_train_X to 5 approximately same folds (approximately, because 123 can't be divided by 5, for example) in order to do a 5-fold cross-validation. Thing described above is my vision of doing it. It may be wrong, that's why i need some advise.

    – Никита Бабенко
    Mar 27 at 17:53
















If i do like this, i get a (123, 3072) array, which i had started with from the beginning. But i need to connect them by first coordinate somehow.

– Никита Бабенко
Mar 27 at 17:41





If i do like this, i get a (123, 3072) array, which i had started with from the beginning. But i need to connect them by first coordinate somehow.

– Никита Бабенко
Mar 27 at 17:41













From your question, I assumed you wanted a 2D array, with the original dimensions. If my assessment is incorrect, please tell what shape you are looking for? What do you mean by "first coordinate"? Or is it the internal order within first_part and second_part that's important?

– mossymountain
Mar 27 at 17:48





From your question, I assumed you wanted a 2D array, with the original dimensions. If my assessment is incorrect, please tell what shape you are looking for? What do you mean by "first coordinate"? Or is it the internal order within first_part and second_part that's important?

– mossymountain
Mar 27 at 17:48













i mean i managed to split the original array(binary_train_X) into 2 arrays: (3, 25, 3072) and (2, 24, 3072). I need to concatenate them somehow to get a one 3-dimensional array of size (5, *, 3072). Original idea is: I need to split binary_train_X to 5 approximately same folds (approximately, because 123 can't be divided by 5, for example) in order to do a 5-fold cross-validation. Thing described above is my vision of doing it. It may be wrong, that's why i need some advise.

– Никита Бабенко
Mar 27 at 17:53





i mean i managed to split the original array(binary_train_X) into 2 arrays: (3, 25, 3072) and (2, 24, 3072). I need to concatenate them somehow to get a one 3-dimensional array of size (5, *, 3072). Original idea is: I need to split binary_train_X to 5 approximately same folds (approximately, because 123 can't be divided by 5, for example) in order to do a 5-fold cross-validation. Thing described above is my vision of doing it. It may be wrong, that's why i need some advise.

– Никита Бабенко
Mar 27 at 17:53

















draft saved

draft discarded
















































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.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55382505%2fhow-to-combine-2-ndarrays-with-different-dimensions%23new-answer', 'question_page');

);

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







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현