MethodError: no method matching -(::NTuple{4,Int64}, ::Int64)

I am new and dont understand why this doesnt work!

original_cost = npzread("file.npy")
size_cost = size(original_cost)
println('size of original table',size_cost)
left_index = 40
right_index = size_cost - left_index
println(left_index, right_index)
cost = copy(original_cost)
cost=cost[left_index:right_index,left_index:right_index,left_index:right_index,left_index:right_index]

with output

size of original table(101, 101, 101, 101)
MethodError: no method matching -(::NTuple{4,Int64}, ::Int64)
Closest candidates are:
  -(!Matched::Complex{Bool}, ::Real) at complex.jl:299
  -(!Matched::Missing, ::Number) at missing.jl:94
  -(!Matched::Base.CoreLogging.LogLevel, ::Integer) at logging.jl:107
  ...

Stacktrace:
 [1] top-level scope at In[9]:5

Hey there! size returns a tuple, not a number. Hence, when you try to substract a number from it you get an error. You might want to use size(original_cost, 1) instead, assuming that the extent in every dimension is the same.

2 Likes

ahh yes, thanks! :slight_smile:

You’re welcome!