Mapping a function to an array of sparse matrices in JuliaIs there a better way to do optional function parameters in JavaScript?What's the difference between a method and a function?var functionName = function() vs function functionName() Set a default parameter value for a JavaScript functionWhat does the exclamation mark do before the function?Efficiently accumulating a collection of sparse scipy matricesJavaScript plus sign in front of function nameHow to efficiently store and manipulate sparse binary matrices in Octave?Similar function to to_scipy_sparse_matrix in Julia sparse matrices functionsIn Julia, The eigs() function for large sparse matrix went wrong
Is a lack of character descriptions a problem?
How can this tool find out registered domains from an IP?
How to safely destroy (a large quantity of) valid checks?
Overlapping String-Blocks
Union with anonymous struct with flexible array member
Wooden cooking layout
I have a problem assistant manager, but I can't fire him
How can I end combat quickly when the outcome is inevitable?
Is it possible to have the age of the universe be unknown?
Is White controlling this game?
How is John Wick 3 a 15 certificate?
How can I make some of my chapters "come to life"?
Should I give professor gift at the beginning of my PhD?
Why didn't Voldemort recognize that Dumbledore was affected by his curse?
What speaks against investing in precious metals?
Teaching a class likely meant to inflate the GPA of student athletes
How does an ordinary object become radioactive?
Pre-1972 sci-fi short story or novel: alien(?) tunnel where people try new moves and get destroyed if they're not the correct ones
Why can my keyboard only digest 6 keypresses at a time?
How to hide an urban landmark?
Using "subway" as name for London Underground?
Certain search in list
Active low-pass filters --- good to what frequencies?
Is it legal for a bar bouncer to confiscate a fake ID
Mapping a function to an array of sparse matrices in Julia
Is there a better way to do optional function parameters in JavaScript?What's the difference between a method and a function?var functionName = function() vs function functionName() Set a default parameter value for a JavaScript functionWhat does the exclamation mark do before the function?Efficiently accumulating a collection of sparse scipy matricesJavaScript plus sign in front of function nameHow to efficiently store and manipulate sparse binary matrices in Octave?Similar function to to_scipy_sparse_matrix in Julia sparse matrices functionsIn Julia, The eigs() function for large sparse matrix went wrong
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I have a 1000-element ArraySparseMatrixCSCFloat64,Int64,1
array of sparse matrices in Julia, named A
, which contains 1000 sparse matrices. I used the command sparse
of the SparseArrays
package of Julia, to store each sparse matrix of the Array. I present an extract below:
julia> A
1000-element ArraySparseMatrixCSCFloat64,Int64,1:
[1 , 1] = 0.994372
[2 , 1] = 0.991773
[3 , 1] = 0.992271
[4 , 1] = 0.998889
[5 , 1] = 0.992853
[6 , 1] = 0.998921
[7 , 1] = 0.98486
[8 , 1] = 0.988783
[9 , 1] = 0.995152
⋮
[1492, 42] = 0.955595
[1493, 42] = 0.982923
[1494, 42] = 0.951944
[1495, 42] = 1.0
[1496, 42] = 0.975999
[1497, 42] = 0.954872
[1498, 42] = 0.963355
[1499, 42] = 0.925815
[1500, 42] = 0.93627
[1 , 1] = 0.975476
[2 , 1] = 0.977395
[3 , 1] = 0.996842
[4 , 1] = 0.996767
[5 , 1] = 0.998007
[6 , 1] = 0.996788
[7 , 1] = 0.959937
[8 , 1] = 0.996806
[9 , 1] = 0.97679
⋮
[1492, 42] = 0.991332
[1493, 42] = 0.999623
[1494, 42] = 0.982065
[1495, 42] = 0.984356
[1496, 42] = 0.998067
[1497, 42] = 0.987055
[1498, 42] = 0.995269
[1499, 42] = 0.977139
[1500, 42] = 0.98173
....
I want to apply the following function to A
:
map(function maxkernLY(x) map(y->y[2],mapslices(findmax, x, dims=2)) end,A)
The function takes each matrix of the Array, and for each row of the selected matrix, it looks for the maximum value. When A
is composed by dense matrices, the function works perfectly, but when A
is composed by sparse matrices like above, I get the following error:
MethodError: no method matching zero(::TypeTupleFloat64,Int64)
Any hint? Could be any Array of sparse matrices, even an array of 2 small sparse matrices, not necessarily the example above.
function julia sparse-matrix
add a comment |
I have a 1000-element ArraySparseMatrixCSCFloat64,Int64,1
array of sparse matrices in Julia, named A
, which contains 1000 sparse matrices. I used the command sparse
of the SparseArrays
package of Julia, to store each sparse matrix of the Array. I present an extract below:
julia> A
1000-element ArraySparseMatrixCSCFloat64,Int64,1:
[1 , 1] = 0.994372
[2 , 1] = 0.991773
[3 , 1] = 0.992271
[4 , 1] = 0.998889
[5 , 1] = 0.992853
[6 , 1] = 0.998921
[7 , 1] = 0.98486
[8 , 1] = 0.988783
[9 , 1] = 0.995152
⋮
[1492, 42] = 0.955595
[1493, 42] = 0.982923
[1494, 42] = 0.951944
[1495, 42] = 1.0
[1496, 42] = 0.975999
[1497, 42] = 0.954872
[1498, 42] = 0.963355
[1499, 42] = 0.925815
[1500, 42] = 0.93627
[1 , 1] = 0.975476
[2 , 1] = 0.977395
[3 , 1] = 0.996842
[4 , 1] = 0.996767
[5 , 1] = 0.998007
[6 , 1] = 0.996788
[7 , 1] = 0.959937
[8 , 1] = 0.996806
[9 , 1] = 0.97679
⋮
[1492, 42] = 0.991332
[1493, 42] = 0.999623
[1494, 42] = 0.982065
[1495, 42] = 0.984356
[1496, 42] = 0.998067
[1497, 42] = 0.987055
[1498, 42] = 0.995269
[1499, 42] = 0.977139
[1500, 42] = 0.98173
....
I want to apply the following function to A
:
map(function maxkernLY(x) map(y->y[2],mapslices(findmax, x, dims=2)) end,A)
The function takes each matrix of the Array, and for each row of the selected matrix, it looks for the maximum value. When A
is composed by dense matrices, the function works perfectly, but when A
is composed by sparse matrices like above, I get the following error:
MethodError: no method matching zero(::TypeTupleFloat64,Int64)
Any hint? Could be any Array of sparse matrices, even an array of 2 small sparse matrices, not necessarily the example above.
function julia sparse-matrix
add a comment |
I have a 1000-element ArraySparseMatrixCSCFloat64,Int64,1
array of sparse matrices in Julia, named A
, which contains 1000 sparse matrices. I used the command sparse
of the SparseArrays
package of Julia, to store each sparse matrix of the Array. I present an extract below:
julia> A
1000-element ArraySparseMatrixCSCFloat64,Int64,1:
[1 , 1] = 0.994372
[2 , 1] = 0.991773
[3 , 1] = 0.992271
[4 , 1] = 0.998889
[5 , 1] = 0.992853
[6 , 1] = 0.998921
[7 , 1] = 0.98486
[8 , 1] = 0.988783
[9 , 1] = 0.995152
⋮
[1492, 42] = 0.955595
[1493, 42] = 0.982923
[1494, 42] = 0.951944
[1495, 42] = 1.0
[1496, 42] = 0.975999
[1497, 42] = 0.954872
[1498, 42] = 0.963355
[1499, 42] = 0.925815
[1500, 42] = 0.93627
[1 , 1] = 0.975476
[2 , 1] = 0.977395
[3 , 1] = 0.996842
[4 , 1] = 0.996767
[5 , 1] = 0.998007
[6 , 1] = 0.996788
[7 , 1] = 0.959937
[8 , 1] = 0.996806
[9 , 1] = 0.97679
⋮
[1492, 42] = 0.991332
[1493, 42] = 0.999623
[1494, 42] = 0.982065
[1495, 42] = 0.984356
[1496, 42] = 0.998067
[1497, 42] = 0.987055
[1498, 42] = 0.995269
[1499, 42] = 0.977139
[1500, 42] = 0.98173
....
I want to apply the following function to A
:
map(function maxkernLY(x) map(y->y[2],mapslices(findmax, x, dims=2)) end,A)
The function takes each matrix of the Array, and for each row of the selected matrix, it looks for the maximum value. When A
is composed by dense matrices, the function works perfectly, but when A
is composed by sparse matrices like above, I get the following error:
MethodError: no method matching zero(::TypeTupleFloat64,Int64)
Any hint? Could be any Array of sparse matrices, even an array of 2 small sparse matrices, not necessarily the example above.
function julia sparse-matrix
I have a 1000-element ArraySparseMatrixCSCFloat64,Int64,1
array of sparse matrices in Julia, named A
, which contains 1000 sparse matrices. I used the command sparse
of the SparseArrays
package of Julia, to store each sparse matrix of the Array. I present an extract below:
julia> A
1000-element ArraySparseMatrixCSCFloat64,Int64,1:
[1 , 1] = 0.994372
[2 , 1] = 0.991773
[3 , 1] = 0.992271
[4 , 1] = 0.998889
[5 , 1] = 0.992853
[6 , 1] = 0.998921
[7 , 1] = 0.98486
[8 , 1] = 0.988783
[9 , 1] = 0.995152
⋮
[1492, 42] = 0.955595
[1493, 42] = 0.982923
[1494, 42] = 0.951944
[1495, 42] = 1.0
[1496, 42] = 0.975999
[1497, 42] = 0.954872
[1498, 42] = 0.963355
[1499, 42] = 0.925815
[1500, 42] = 0.93627
[1 , 1] = 0.975476
[2 , 1] = 0.977395
[3 , 1] = 0.996842
[4 , 1] = 0.996767
[5 , 1] = 0.998007
[6 , 1] = 0.996788
[7 , 1] = 0.959937
[8 , 1] = 0.996806
[9 , 1] = 0.97679
⋮
[1492, 42] = 0.991332
[1493, 42] = 0.999623
[1494, 42] = 0.982065
[1495, 42] = 0.984356
[1496, 42] = 0.998067
[1497, 42] = 0.987055
[1498, 42] = 0.995269
[1499, 42] = 0.977139
[1500, 42] = 0.98173
....
I want to apply the following function to A
:
map(function maxkernLY(x) map(y->y[2],mapslices(findmax, x, dims=2)) end,A)
The function takes each matrix of the Array, and for each row of the selected matrix, it looks for the maximum value. When A
is composed by dense matrices, the function works perfectly, but when A
is composed by sparse matrices like above, I get the following error:
MethodError: no method matching zero(::TypeTupleFloat64,Int64)
Any hint? Could be any Array of sparse matrices, even an array of 2 small sparse matrices, not necessarily the example above.
function julia sparse-matrix
function julia sparse-matrix
asked Mar 24 at 18:00
coolsvcoolsv
1157
1157
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Does this:
getindex.(findmax.(A, dims=2), 2)
give you what you want? (a slight difference from your code is that it returns indices within the whole arrays not within rows, but this can be simply fixed if you do not like it; in practice these double indices might be even easier to work with later).
Regarding your original code - this seems to be a bug in Julia. Which is confirmed when you read the definition of setindex!
around line 2677 in SparseArrayssrcsparsematrix.jl.
EDIT
If you want to use mapslices
you can use something like this:
map(x -> mapslices(t -> collect(findmax(t)), x, dims=2)[:, 2], A)
or
getindex.(mapslices.(t -> collect(findmax(t)), A, dims=2), :, 2)
this will give you an equivalent result to your original code.
Ok I will try and keep you posted ;-) Thanks
– coolsv
Mar 25 at 2:22
The second option of the EDIT part works fine :-) the first option gives an error: Out of Bonds error
– coolsv
Mar 26 at 15:30
fixed - I copy-pasted part of the code and forgotten to fix it.
– Bogumił Kamiński
Mar 26 at 15:53
Ok perfect! Thank you!
– coolsv
Mar 26 at 16:10
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%2f55326817%2fmapping-a-function-to-an-array-of-sparse-matrices-in-julia%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Does this:
getindex.(findmax.(A, dims=2), 2)
give you what you want? (a slight difference from your code is that it returns indices within the whole arrays not within rows, but this can be simply fixed if you do not like it; in practice these double indices might be even easier to work with later).
Regarding your original code - this seems to be a bug in Julia. Which is confirmed when you read the definition of setindex!
around line 2677 in SparseArrayssrcsparsematrix.jl.
EDIT
If you want to use mapslices
you can use something like this:
map(x -> mapslices(t -> collect(findmax(t)), x, dims=2)[:, 2], A)
or
getindex.(mapslices.(t -> collect(findmax(t)), A, dims=2), :, 2)
this will give you an equivalent result to your original code.
Ok I will try and keep you posted ;-) Thanks
– coolsv
Mar 25 at 2:22
The second option of the EDIT part works fine :-) the first option gives an error: Out of Bonds error
– coolsv
Mar 26 at 15:30
fixed - I copy-pasted part of the code and forgotten to fix it.
– Bogumił Kamiński
Mar 26 at 15:53
Ok perfect! Thank you!
– coolsv
Mar 26 at 16:10
add a comment |
Does this:
getindex.(findmax.(A, dims=2), 2)
give you what you want? (a slight difference from your code is that it returns indices within the whole arrays not within rows, but this can be simply fixed if you do not like it; in practice these double indices might be even easier to work with later).
Regarding your original code - this seems to be a bug in Julia. Which is confirmed when you read the definition of setindex!
around line 2677 in SparseArrayssrcsparsematrix.jl.
EDIT
If you want to use mapslices
you can use something like this:
map(x -> mapslices(t -> collect(findmax(t)), x, dims=2)[:, 2], A)
or
getindex.(mapslices.(t -> collect(findmax(t)), A, dims=2), :, 2)
this will give you an equivalent result to your original code.
Ok I will try and keep you posted ;-) Thanks
– coolsv
Mar 25 at 2:22
The second option of the EDIT part works fine :-) the first option gives an error: Out of Bonds error
– coolsv
Mar 26 at 15:30
fixed - I copy-pasted part of the code and forgotten to fix it.
– Bogumił Kamiński
Mar 26 at 15:53
Ok perfect! Thank you!
– coolsv
Mar 26 at 16:10
add a comment |
Does this:
getindex.(findmax.(A, dims=2), 2)
give you what you want? (a slight difference from your code is that it returns indices within the whole arrays not within rows, but this can be simply fixed if you do not like it; in practice these double indices might be even easier to work with later).
Regarding your original code - this seems to be a bug in Julia. Which is confirmed when you read the definition of setindex!
around line 2677 in SparseArrayssrcsparsematrix.jl.
EDIT
If you want to use mapslices
you can use something like this:
map(x -> mapslices(t -> collect(findmax(t)), x, dims=2)[:, 2], A)
or
getindex.(mapslices.(t -> collect(findmax(t)), A, dims=2), :, 2)
this will give you an equivalent result to your original code.
Does this:
getindex.(findmax.(A, dims=2), 2)
give you what you want? (a slight difference from your code is that it returns indices within the whole arrays not within rows, but this can be simply fixed if you do not like it; in practice these double indices might be even easier to work with later).
Regarding your original code - this seems to be a bug in Julia. Which is confirmed when you read the definition of setindex!
around line 2677 in SparseArrayssrcsparsematrix.jl.
EDIT
If you want to use mapslices
you can use something like this:
map(x -> mapslices(t -> collect(findmax(t)), x, dims=2)[:, 2], A)
or
getindex.(mapslices.(t -> collect(findmax(t)), A, dims=2), :, 2)
this will give you an equivalent result to your original code.
edited Mar 26 at 15:52
answered Mar 24 at 23:07
Bogumił KamińskiBogumił Kamiński
17.3k21726
17.3k21726
Ok I will try and keep you posted ;-) Thanks
– coolsv
Mar 25 at 2:22
The second option of the EDIT part works fine :-) the first option gives an error: Out of Bonds error
– coolsv
Mar 26 at 15:30
fixed - I copy-pasted part of the code and forgotten to fix it.
– Bogumił Kamiński
Mar 26 at 15:53
Ok perfect! Thank you!
– coolsv
Mar 26 at 16:10
add a comment |
Ok I will try and keep you posted ;-) Thanks
– coolsv
Mar 25 at 2:22
The second option of the EDIT part works fine :-) the first option gives an error: Out of Bonds error
– coolsv
Mar 26 at 15:30
fixed - I copy-pasted part of the code and forgotten to fix it.
– Bogumił Kamiński
Mar 26 at 15:53
Ok perfect! Thank you!
– coolsv
Mar 26 at 16:10
Ok I will try and keep you posted ;-) Thanks
– coolsv
Mar 25 at 2:22
Ok I will try and keep you posted ;-) Thanks
– coolsv
Mar 25 at 2:22
The second option of the EDIT part works fine :-) the first option gives an error: Out of Bonds error
– coolsv
Mar 26 at 15:30
The second option of the EDIT part works fine :-) the first option gives an error: Out of Bonds error
– coolsv
Mar 26 at 15:30
fixed - I copy-pasted part of the code and forgotten to fix it.
– Bogumił Kamiński
Mar 26 at 15:53
fixed - I copy-pasted part of the code and forgotten to fix it.
– Bogumił Kamiński
Mar 26 at 15:53
Ok perfect! Thank you!
– coolsv
Mar 26 at 16:10
Ok perfect! Thank you!
– coolsv
Mar 26 at 16:10
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.
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%2f55326817%2fmapping-a-function-to-an-array-of-sparse-matrices-in-julia%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