I have a matrix matrix = [["22", "na", "na"], ["na", "na", "16"], ["na", "25", "na"]]
and now I am trying to count the positions of numbers and return something like this [{"22", 1}, {"16", 6}, {"25", 8}] .
The number “22” got position as 1 because it’s the first element ( even though it’s index is 0) and the same applies for all the elements in the expected.
I tried the following matrix |> List.flatten() |> Enum.with_index() |> Enum.filter(fn x -> !is_integer(x) end) |> Enum.to_list()
which ends up giving me [ {"22", 0}, {"na", 1}, {"na", 2}, {"na", 3}, {"na", 4}, {"16", 5}, {"na", 6}, {"25", 7}, {"na", 8} ] . as the output , help is much appreciated.
You need to look at what data structure is output from Enum.with_index. Put an IO.inspect() between each of your pipeline steps to see what the data is.
Do you think is_integer is going to return true for anything in your input data? Hint, all your data points are strings. Look at the String and Integer module docs for something that will parse a string to an integer.
You’re also going to need to add 1 to the index at some point.
bro please help me to convert grid image to matrix in elixir. do you have any idea about it? from your question it seems like you have done it before. help is much appreciated.