How do I find the size of a Matrix object?

I found the code below on the web, it is quite standard. It looks like it worked at some point in the past. It does not work today in my system (Windows 11 Pro, Julia 7.3). Does anyone know why and how do I find the dimensions of an object of type Matrix?

(I would like to find that A below is a 2 x 3 matrix or array)

A =  [2 -4 8.2; -5.5 3.5 63]
typeof(A) # Matrix{Float64} (alias for Array{Float64, 2})
# ERROR: MethodError: objects of type Int64 are not callable
# Maybe you forgot to use an operator such as *, ^, %, / etc. ?

I found that DataFrames.size(A) works. Probably there was a conflict with another package.

The error you get after you try


probably means that you had already assigned an Int64 value to a variable you called ‘size’ on the global scope.
This would have masked the call to DataFrames.size when using it without the Module name (i.e. DataFrames).

When you post questions here it’s always a good idea to rerun the code snippet you’re posting on a fresh Julia session to ensure others can reproduce the issue. In this case it would also have had the benefit of giving you the answer straightaway!

1 Like

Not necessarily in my opinion.
If the variable ‘size’ was assigned on the REPL then yes, a fresh session would fix the issue.
But what if the assignment is inside the file that he is trying to run?

Then, for a beginner, I think it would be very difficult to know what they have to include in the snippet.

By running the snippet in a fresh session, they would realize that the problem was not in that snippet, but lay elsewhere, so the advice still applies.

1 Like

that’s true