max(A, A') gives isless() error

I am trying to generate a graph G by taking maxof SparseArrays.SparseMatrixCSC{Float64, Int64}
and LinearAlgebra.Adjoint{Float64, SparseArrays.SparseMatrixCSC{Float64, Int64}}

But it throws me an error when I do
G = max(A, A’); # undirected version of graph

My original code is:

using MatrixNetworks
using MAT
using PyPlot
using PyCall

data = matread(“data/neuronal.mat”);
A = data[“A”];
G = max(A, A’);

It runs fine till A, but throws error at G. Don’t know how to solve it.

I tried import Base: isless but no help.

This is the error:

MethodError: no method matching isless(::LinearAlgebra.Adjoint{Float64, SparseArrays.SparseMatrixCSC{Float64, Int64}}, ::SparseArrays.SparseMatrixCSC{Float64, Int64})
Closest candidates are:
isless(::Any, ::Missing) at missing.jl:88
isless(::Missing, ::Any) at missing.jl:87
isless(::Any, ::PyObject) at C:\Users\Manish.julia\packages\PyCall\ygXW2\src\pyoperators.jl:76

[1] max(x::SparseArrays.SparseMatrixCSC{Float64, Int64}, y::LinearAlgebra.Adjoint{Float64, SparseArrays.SparseMatrixCSC{Float64, Int64}})
@ Base .\operators.jl:480
[2] top-level scope
@ In[29]:1
[3] eval
@ .\boot.jl:368 [inlined]
[4] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
@ Base .\loading.jl:1428

In order to calculate max(A, A') it must be possible to say which one is ‘greater’, and isless helps with that comparison.

But what is greater of A and A'? I don’t think there is any obvious answer to that question.

My guess is that you probably want to compare element-by-element, and to do that you can use broadcasting:

max.(A, A')

Notice the dot after max. This should return a matrix with pairwise comparisons of all elements.

Take a look at the broadcasting section of the manual for more information: Multi-dimensional Arrays · The Julia Language

1 Like

This helped. Thanks a lot.