I have a 2D array of size 150x150, and for debugging purposes, I want to see in the REPL where the NaNs are in this array.
How would you do that?
I have a 2D array of size 150x150, and for debugging purposes, I want to see in the REPL where the NaNs are in this array.
How would you do that?
Are the NaNs sparse? Use a sparse array! It’s quick and dirty, but… it’s quick ![]()
julia> A = rand(150,150);
julia> A[A .< .1] .= NaN;
julia> using SparseArrays
julia> sparse(isnan.(A))
150×150 SparseMatrixCSC{Bool, Int64} with 2250 stored entries:
⎡⢐⠔⠂⡄⢆⡊⠢⢀⡀⠀⢠⢀⡄⢂⠁⡃⡀⢀⠔⢂⡀⢀⠂⢀⠀⠀⠀⡠⢐⠠⠐⡈⠆⠀⠋⠀⢨⢀⠉⢸⠁⡀⠓⠈⡃⠀⠠⢰⢒⢀⢈⠄⎤
⎢⠀⠈⠀⠱⠂⡠⠀⢀⠰⠀⠬⠈⠁⠣⢐⠈⠀⠰⠀⢠⢠⠀⠠⠈⠐⠄⠤⠐⠥⠜⠢⠀⠄⠂⡅⠠⠀⠀⠀⠀⠀⠄⠅⠆⠅⠂⠐⠠⠡⠄⠤⠀⎥
⎢⢩⠡⠀⠠⠁⠁⠀⡈⠁⠈⠈⠔⠈⠁⠡⠃⡘⠈⠐⠀⠡⠉⠄⠄⢄⠁⠐⠸⢉⠢⠀⠈⠌⠀⠩⢀⠠⠄⢠⢙⠁⡀⠉⢠⠅⠒⡀⢳⡀⠠⡢⠠⎥
⎢⢐⠠⠈⠒⠌⠄⡄⣀⠥⠀⠼⢀⠀⢐⡁⡁⠄⢐⠈⠁⠖⡊⡁⠁⠀⠀⠃⠂⠠⠄⠄⠡⠊⣈⢀⠤⢜⠀⡁⠝⠨⣅⣡⠀⡀⢀⣈⠀⣁⢀⢌⠀⎥
⎢⠒⠂⠂⠄⣅⡁⢀⢂⡀⣐⣃⠐⠀⠂⡆⢕⠀⠀⠀⣐⡐⠀⡆⡀⠕⡂⡐⡐⡐⢀⠆⠂⠛⣄⠐⠀⠐⢠⠀⡂⠇⠊⠃⠖⡂⢀⠀⠈⢀⣠⠂⣀⎥
⎢⢠⠰⣈⠘⠕⠁⠃⠐⡴⣐⠐⠀⠈⠂⠀⠃⡂⣂⠐⠸⠔⢀⠒⠑⠒⡅⠲⠀⠒⠀⠀⠞⠄⡆⠀⢀⢖⡰⡀⠐⢂⢀⠀⠲⠢⠂⠰⠸⠠⠀⡂⠂⎥
⎢⠡⠀⢊⠁⠀⣠⠈⠨⠀⠠⠀⡌⠬⠔⣁⡅⠠⢄⢁⠭⠠⠁⢀⠇⠂⠈⠈⠊⠀⢊⢈⠆⣄⠌⠄⠈⠃⢌⠀⠰⢀⠠⠡⡈⡀⠡⠐⠀⠠⡀⢄⠄⎥
⎢⠢⠨⠄⡤⠈⠇⡠⠀⢄⠉⠐⠁⠅⠠⠡⠀⠜⠤⠈⠠⢡⣠⠥⠁⠈⢄⠁⠀⡀⡄⠀⠥⡈⠙⠅⢉⠈⠈⠊⠀⠁⡀⠄⠁⠁⠂⡠⠈⠀⠀⢃⠅⎥
⎢⣈⠰⣄⣁⡇⠀⢉⠀⠔⢁⠀⠀⠈⢌⢀⠀⠀⠜⠂⡈⢃⠨⠄⡂⠁⠀⠈⠈⠌⢑⠀⠀⢀⠈⡂⡌⠰⠀⠈⠤⠈⡁⠁⣀⢉⠑⢀⡄⠀⢀⢊⠂⎥
⎢⢐⢀⠑⢒⠀⠀⠂⢀⣀⠂⠂⠁⠐⡆⠅⡂⠀⢀⠂⠀⢎⢀⡄⠂⡂⢀⣁⢁⢐⢒⡘⠄⠦⠄⠀⠀⠐⢲⠞⢢⢀⠀⠀⡂⡀⡀⠠⠀⠰⣂⣈⠈⎥
⎢⠖⠀⠀⠂⠠⠁⠂⠈⠀⢀⠁⢀⢀⠀⡪⠀⡀⠀⠀⠀⠀⡁⠀⢠⡠⢀⠀⠁⡫⠘⡔⠀⠂⢌⢄⠒⠀⠒⡠⠠⠐⡀⣂⡊⢂⠜⠀⢒⠀⠂⠂⠀⎥
⎢⡅⠠⠤⡉⠪⠠⠨⠸⠈⠭⠄⠈⠉⠀⡋⡥⡁⠅⠀⠄⠀⠃⡄⠀⠁⠄⠠⠠⠮⠐⡠⠁⠃⠄⢥⠊⢠⢨⢀⠹⠂⠈⡁⠑⢠⠱⠀⠄⢀⠈⠀⠠⎥
⎢⠄⠨⢤⠀⠨⠔⠀⠠⢼⡀⠀⠘⢄⡢⠀⢄⠀⠀⡌⠊⢀⠤⠌⠃⠐⠂⢍⠄⠀⠁⠀⠦⠀⡊⡃⠡⠐⠊⠠⠈⠀⠀⠌⠄⠁⢀⠀⠀⠨⠁⠅⠔⎥
⎢⠠⠰⠀⡥⢌⡀⡆⢈⠂⠈⠀⠀⠪⠂⡀⡀⢄⠢⠒⠐⠀⠀⡀⢀⢀⡂⠀⢄⡘⢑⢂⡂⠈⠀⠒⠀⠀⠔⠒⢓⠁⠀⠊⡀⡄⠀⠄⣀⢂⡄⠔⡢⎥
⎢⢔⢐⠀⢊⡀⣄⣗⢈⠠⣈⠺⢀⠀⠆⠀⡄⠀⠀⠐⠀⠀⠀⡴⢖⡟⠂⠀⡖⢂⠐⠠⡀⠀⠀⡄⠲⠠⢐⣐⠀⠀⡁⢂⠐⠀⢀⢌⠀⠀⠁⠀⠨⎥
⎢⠄⡀⠀⠅⠀⠠⠁⠐⠠⠁⠠⠀⡢⠄⡀⢈⠄⠀⠐⠀⢘⠂⠆⠤⠁⠄⠠⡂⠀⠠⠁⠀⠄⠄⠥⢰⣰⢄⢐⠄⠄⡄⡀⡀⠠⢡⠠⠈⡧⠨⠀⠀⎥
⎢⠁⣈⢃⢀⠥⠁⠁⠰⠖⠜⠁⠈⠄⠖⠄⠠⠂⢑⠨⡐⠀⠄⠍⢦⠄⠢⠍⠠⠡⠐⠀⠔⡄⠁⡀⠙⠨⠍⠰⠨⡀⠡⡇⠃⠀⠐⠈⠠⡇⠂⠋⠢⎥
⎢⢈⢉⢆⡀⣄⠀⡀⠘⠀⢀⢤⠀⣀⢅⡄⢈⠏⣁⢈⣡⢈⡁⡀⠁⠠⣄⢉⢄⠭⣐⠀⠂⢓⡀⣐⡈⠀⡀⠈⠀⢀⠁⠈⠀⡀⠀⡄⢘⠍⢄⠡⡤⎥
⎢⢰⠈⠰⡀⠀⠀⠄⡄⣀⢄⢀⠁⡄⡀⡀⡆⠒⢔⢈⠁⠄⢠⠀⠀⠄⠆⠂⣀⡄⠐⡀⢅⡐⡀⢁⢘⢰⠷⠐⠨⠀⠂⠀⣚⣀⣀⠀⢐⢀⠂⠂⠀⎥
⎢⠠⠐⠀⣀⡆⠂⣐⠄⡁⠰⠂⠀⠄⡀⡌⠢⠀⢠⢀⠐⠡⠐⠐⠃⡂⠕⠪⠢⡀⠐⠄⠄⣀⡀⠁⠠⢑⠀⢀⢐⠁⡃⡀⡔⡡⠀⡐⢀⠈⠀⡈⠂⎥
⎢⢠⠰⢀⠀⠤⢁⠄⠠⠀⠢⠐⠀⡤⠀⢔⡂⡈⠀⠆⠀⢂⠤⠅⠀⢄⢁⠀⠐⠠⢙⠔⡀⠀⠰⠀⠠⡠⠀⠀⠠⠀⡥⡠⠢⠂⠠⠚⠠⠈⠀⠆⢅⎥
⎢⠈⠀⢀⠂⢆⠢⠄⠀⠅⠐⡨⠡⠂⠡⠉⠄⡀⠙⠒⠈⠈⠐⠀⠂⠉⠥⢀⠬⠀⢈⠈⠅⠀⡉⠁⠉⠐⠩⠐⠙⠀⠒⠀⠁⢀⠀⢀⠠⠡⠀⢂⡀⎥
⎢⠥⡁⠠⢂⡁⡈⠙⢠⠐⠀⠐⠨⠁⡁⡂⠀⣄⠀⢀⢓⡀⢠⠉⡄⠈⡛⠘⣐⡀⢍⠀⡀⠀⡀⢀⠨⢐⢥⢉⢀⢀⠃⠃⠄⣀⢐⠀⢠⠠⠀⠂⠄⎥
⎢⢘⠢⠂⡀⡁⢄⠀⠀⡠⠀⠓⠐⠁⠂⢂⡁⡀⠀⠀⢓⣃⡀⠀⡀⡷⢃⠐⢘⠠⣀⠀⠐⠀⡉⣐⠨⠑⣠⠀⠐⢔⡂⠃⠍⢀⠐⣀⠀⠂⡁⠓⠀⎥
⎢⠢⢀⠀⠀⠀⠄⡢⠀⠰⠐⠀⠀⡖⠀⡁⠀⠊⠱⠴⠀⠀⡈⠁⠬⠂⠀⠀⠚⠐⠐⠀⠢⠂⠀⠤⠰⠀⠈⠀⢂⡐⡁⠐⠄⡄⠐⠈⠐⢀⠀⠀⡀⎥
⎣⢨⡄⠀⡐⡁⠔⠈⠈⢀⠡⠠⠄⠠⢁⡣⡁⠇⠢⠙⠀⡐⢀⠂⠡⠢⢠⠀⢠⢌⢉⠤⠣⠄⡠⠄⠃⠀⠈⢔⡠⡐⠀⠠⠆⠄⠘⠀⠍⠢⡌⠉⠀⎦
Thank you a lot, it looks very nice!
Follow-up question: How can I check if any element of my array is NaN?
julia> any(isnan, A)
true
I have been using Julia for 12 years, and I still learn new functions every other week. ![]()
If you want to be extra fancy, you can also use Plots.spy with UnicodePlots for REPL output. ![]()
julia> using UnicodePlots
julia> A = rand([0, NaN], 150, 150);
julia> spy(isnan.(A); width=60, height=30)
┌────────────────────────────────────────────────────────────┐
1 │⣛⣟⣭⣻⣹⣽⣟⢹⢹⣫⣽⣽⣼⣿⣢⡞⣎⣈⣛⠇⣭⡇⣞⣝⢋⣛⣫⣗⣿⣷⣩⣭⣾⣩⣻⣚⢽⣉⣻⡏⢫⣝⡞⢣⠹⡫⣕⢼⣏⢙⣭⣻⢿⠕⣩⢭⣥⡗⣏⠅│ > 0
│⡳⢫⣎⢌⣣⣫⢵⢼⢀⣾⣰⢶⡐⣫⣹⡗⣟⢚⣆⡍⣌⣟⠏⡙⣝⡏⢽⣾⢇⡗⣏⣭⣻⣋⣺⡧⣴⣩⢭⣝⣲⣃⣴⣝⣩⣥⣏⢚⣆⣑⡟⣩⡕⢵⣽⣃⣯⢀⣏⡄│ < 0
│⡫⣟⠔⣽⣤⣾⢚⢝⣋⡟⢂⣚⣣⣚⣣⡇⣑⢧⡯⣇⡻⣓⣷⣰⠈⣗⣢⣽⣐⣨⠿⣱⣑⢩⣫⣅⢔⡧⣑⣲⢛⣵⣩⣚⢛⣉⣧⣛⣖⢸⣒⣅⣗⣝⣟⡅⣗⡴⣿⡃│
│⣫⣺⣙⢿⣵⣺⣘⣽⡱⢏⣞⣹⠸⣶⢀⡖⣴⣮⠛⣟⢢⡮⣤⣪⣦⡏⣝⣦⣡⣐⣿⣩⣶⢒⣉⢍⣻⣷⣾⣼⡺⡽⢧⡵⣨⣅⡇⢼⣟⣼⣯⣟⣠⣟⡲⢸⡳⣁⡱⡃│
│⣿⣨⡇⢵⣃⣩⡴⣷⣞⢍⡌⢍⣔⣫⣁⣖⡢⡌⡽⠷⢳⣘⣾⣾⣹⣝⢋⣵⣶⣅⢾⡧⣓⠳⣻⠸⣞⡜⢏⡼⢽⣇⣶⣀⣗⣨⣖⣴⡇⣸⣣⡜⣛⢶⣞⣥⣷⣪⣏⠂│
│⣇⣖⣡⢞⡈⢹⣜⢛⡔⣚⣎⡪⠘⣠⣅⣿⡒⡥⣕⣌⢾⣶⡃⣿⣭⢯⡴⢧⣫⢗⣾⡷⢿⣑⣈⣣⣳⡴⣘⣫⣝⢫⣕⣌⢜⣒⡽⡡⡣⣫⡫⣵⣇⢆⣴⣡⣗⡻⣥⡇│
│⣷⢎⣐⣼⢌⣙⣘⢖⣉⣨⣫⢸⣳⣏⡂⣣⣘⡽⣹⡿⣄⣯⣮⣛⣺⡿⡭⣋⢷⣍⡦⣕⣙⠱⣻⣔⣩⡖⣮⠬⣾⢑⣾⢴⢝⣜⣵⣪⣏⣱⣱⡙⢿⢲⣏⢚⣯⢉⣷⡆│
│⢧⡸⣏⢽⠗⣱⣡⢭⠼⠼⠤⣵⡷⢮⡫⡿⠫⣮⢯⣆⡷⡿⠱⡿⡯⢕⢽⠟⠖⣇⢴⢬⣼⣢⢬⢾⡽⡭⣯⡡⢻⣾⢜⡜⡼⠮⡯⠧⢭⠿⣽⣭⣷⣟⡽⠘⡇⢩⣷⡆│
│⣿⢺⡶⣿⢧⡶⣠⠶⡅⢺⠕⡜⢡⣾⢾⣭⢾⠇⢪⣷⠯⡥⢩⡦⡼⣵⠍⢯⡍⡥⢺⠷⢾⠱⣷⠧⢿⠮⢻⠞⠮⣹⢽⠇⠽⡭⢷⠤⡯⢱⡿⣋⡷⠾⡦⠸⡦⡴⠦⡁│
│⣽⢺⠵⣶⠼⣫⠴⡰⣻⢴⡭⠬⠲⣴⣧⠌⢿⣭⠯⣟⡾⢯⠿⢦⢼⠥⣮⡷⣽⣷⣏⠼⢹⢭⣴⣆⣼⡶⢿⢬⢼⠡⣒⡶⡽⡥⠗⣠⡗⢆⣗⠷⣿⢵⠿⣇⣻⠖⢯⡄│
│⣽⢏⡜⢦⢵⡺⢇⡮⡭⣿⢝⢿⠅⣴⣦⡤⣭⣶⣲⠏⢭⠍⡤⠯⡰⣄⠼⢥⠎⠆⢼⣷⣼⠊⣷⠱⡥⢧⢳⢙⡽⠏⢸⣫⢯⣭⠍⢨⡷⣾⡗⡶⡷⢶⡿⣺⡬⠑⣗⠃│
│⢷⠿⢲⡾⢾⡽⢼⢞⡪⢸⣠⢭⢵⢼⢿⡤⡌⣧⣞⠖⣕⡧⢉⡟⢤⡧⡞⢍⢑⡭⢼⣇⠼⠦⣾⢗⡾⡂⢼⣥⡿⠯⢻⣾⣤⡔⡝⠿⢿⡯⣶⡻⡴⣲⢗⢤⡭⡷⡅⠅│
│⡧⢫⢒⠵⠬⠺⢣⢵⠟⢝⢘⡹⣢⡲⡿⣥⢦⡏⠼⡮⡢⣟⣤⡿⡸⠊⠗⣟⣭⠿⣨⣱⠾⡬⡵⠶⡾⠧⣾⢮⣤⠥⣯⢣⣽⡾⣵⠞⡯⣢⠶⠏⣿⢞⡷⢡⡧⠹⢥⠄│
│⡽⣬⣷⣿⠼⣽⣥⣹⠮⢯⣎⣖⠦⣽⣮⣵⠴⣇⡔⡿⠫⣏⣥⡿⡭⡴⣔⣾⣎⣿⡾⠵⢲⣼⡶⠭⡬⡄⡠⣴⣼⢢⢝⣬⣩⢯⡼⢡⡇⠴⡾⡞⢷⣯⡏⢫⡧⣜⣿⡅│
│⡵⣼⢮⢭⡝⢺⢯⢼⠧⢴⡵⣮⢤⢤⡊⡶⠮⣷⡬⠷⠷⢟⣴⢮⠝⡿⠴⣵⢵⡷⢸⢥⢵⣃⢵⡉⠶⢼⢻⠭⣾⡭⢬⣬⢝⠟⡯⠶⠿⢪⣟⢵⡗⣶⠥⠨⠿⠁⡭⠂│
│⣿⣳⢴⢙⣑⣩⢦⣲⡛⣾⢨⢷⢱⢚⢷⣗⣚⡟⣞⡿⡛⡳⣂⠖⠇⣷⠗⡷⣷⣓⡿⣛⡱⣚⢶⢚⡽⣲⣑⡿⣲⣟⡾⠦⢹⣢⢷⠒⢯⣖⡗⢼⣓⣳⣻⡻⣇⢷⠟⡆│
│⣛⣼⢐⢼⢒⢹⣬⣿⠗⣸⣟⣻⢿⢺⢚⣮⠒⡛⠟⡷⢌⣗⡝⢛⣟⣓⠵⠇⡰⡗⢾⢵⢻⢲⢶⡑⢺⠇⠴⠓⡿⣚⣕⡫⣯⣻⡞⣽⡷⡁⡗⡞⠮⡜⡟⢝⡷⠞⣷⡆│
│⣛⣺⢻⣴⣺⢶⠳⠻⡳⡳⡲⢹⠓⢻⣓⡛⢢⡟⠿⡗⣻⠗⠸⠳⢓⣿⣶⣖⠲⣟⢳⣻⡾⣶⢽⠖⢚⠽⢿⡲⢿⢾⢞⣟⢟⢦⣗⡞⡺⡔⠛⠨⣏⠳⣺⢲⡿⢰⣞⠆│
│⣥⢺⠗⡽⡏⢦⢟⣗⡞⢖⠳⢛⠃⣝⣷⣿⣾⠏⣛⣳⡵⣟⢻⣷⡹⡳⢿⠗⡳⡓⢽⣍⠺⣿⠲⢛⡺⡺⢻⢺⣹⡣⣚⢗⡿⣶⠷⣻⣚⣛⡦⡓⡼⠌⣣⠞⡗⠞⡓⡀│
│⡶⡿⢴⡿⢗⠮⣻⡛⢎⢾⠐⢻⣝⢺⡳⠿⢾⡿⢒⡿⣾⡟⢖⠗⠳⣦⢻⠯⢲⣧⢒⠿⣻⣪⢳⢯⡝⡰⢻⠊⢾⠪⣺⡓⣺⣪⣿⢾⡿⠍⡟⠷⢿⢕⣒⡝⣗⠷⣞⡆│
│⢗⣿⠷⢿⠒⠚⠵⣳⡒⠿⣞⡸⣓⢻⡛⠧⣗⣯⢽⡗⠻⣻⢔⢷⣧⡣⠴⣲⠏⠯⣺⣳⢷⡶⣙⣗⣾⢆⠘⢺⢙⡣⣟⡹⢽⠋⠇⠫⣝⠶⡯⣱⠜⣘⡓⢟⣗⠞⣏⠄│
│⡳⣻⢺⣽⡹⣞⣕⢟⡵⣹⢒⡻⡞⠞⠝⣚⣸⣞⡔⢳⠾⡾⣸⡝⣹⡗⣳⡎⣧⠏⢻⠰⣾⠇⡖⡒⡾⣝⠿⡟⠟⢣⣼⡑⢊⡗⢷⡊⣧⠮⣟⢸⢟⣾⡟⣾⡻⣲⡷⠅│
│⣟⡟⣳⣻⠂⢞⠖⡇⠵⣟⣹⣺⡊⠽⠍⠪⣋⡿⣺⣞⡗⣟⡃⣯⠚⡢⠃⡧⣎⡾⢻⣝⠻⠟⣐⢬⣻⠛⠾⢛⣺⣆⡸⡖⢛⢮⣻⣶⡶⢿⣆⡓⣂⡛⡟⠙⢿⢿⣏⡆│
│⡟⣿⣹⢺⣉⣯⠩⢯⢁⢿⡻⣿⠯⣛⠏⡏⠉⣿⣏⣝⣜⣟⣭⡷⠡⡯⡫⣯⡧⡷⢛⢭⣟⠃⢿⠋⢎⡭⡹⢩⣫⡭⣺⠙⢭⣿⡮⠍⣟⠸⠁⠫⡏⡤⡟⢺⣮⠋⣭⠅│
│⠗⣫⣹⢯⠿⣨⢗⠿⠍⢻⠫⣙⡱⠻⡭⡏⡫⡝⡛⣡⢪⣧⢜⣿⠀⠿⡟⣱⠻⣿⣛⢮⡭⠩⠍⠉⣾⡽⠼⣂⡺⠲⢿⡻⡟⣫⡝⢃⣭⡫⣏⡣⣭⠛⡧⣍⢳⢶⣭⡁│
│⡽⢟⡶⣝⣫⢻⡫⣿⠽⢯⠟⢿⠎⡩⠵⣍⠯⣛⡈⣻⡊⢝⢍⣑⠹⣳⡝⣕⡛⣧⢽⢨⡽⠞⠩⡓⣱⡅⢼⣉⢻⢟⣽⣹⠻⣓⡇⢳⢟⣬⣒⡾⡻⣋⢗⢁⣋⡄⠿⡇│
│⠟⡜⣙⠼⢳⡱⡿⣼⡛⢻⢃⡿⢮⣭⠜⡟⢊⡍⠙⠺⡷⣝⣺⡻⡙⠿⡭⠛⢹⣏⣌⣝⣼⡣⢻⣟⣭⡎⣌⣻⣮⠽⢛⠲⢻⣬⣮⠉⢧⡳⣉⣩⣟⠃⣍⢨⣏⣙⢏⡅│
│⡯⢿⢩⢋⠟⣝⠉⢲⠃⢵⡷⢿⠍⢭⣽⠫⡹⡯⣷⡗⢎⠏⢭⡏⠅⡫⢈⣭⡋⡫⣹⣳⣹⢌⣩⠏⣹⣝⠑⡙⢿⠩⢙⡿⡧⠉⡝⡚⣟⢚⣇⠏⣷⢙⢿⢷⣿⢥⡓⡃│
│⢙⣩⢃⣭⣚⣉⢽⡸⢋⢹⣯⠚⣭⣩⢫⣍⢵⣏⢫⣭⠂⡵⣩⣪⣿⣿⢩⣷⡢⡵⣏⡹⣽⢋⣹⣜⡕⢍⣹⢈⣩⠩⣟⣭⣫⠓⡹⢏⡝⡍⢙⠫⣮⠟⣏⡋⡿⠻⢍⠇│
150 │⠋⠹⠋⠫⠋⠹⠑⠙⠻⠑⠪⠿⠏⠽⠋⠇⠫⠿⠥⠉⠃⠻⠭⠁⠡⠏⠣⠁⠻⠝⠜⠭⠽⠮⠿⠍⠵⠹⠻⠉⠙⠣⠾⠝⠽⠾⠍⠯⠭⠩⠋⠇⠽⠏⠅⠏⠇⠈⠛⠁│
└────────────────────────────────────────────────────────────┘
⠀1⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀150⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀11 223 ≠ 0⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
(The output even comes in color in my local REPL.)
Using the following code now:
if any(isnan, rel_vel)
println(" Warning: NaN values found in relative velocity field!")
display(sparse(isnan.(rel_vel)))
end
Key point: use display, not println.
Nice result:
.DEBUG FlowField:
Warning: NaN values found in relative velocity field!
286×701 SparseArrays.SparseMatrixCSC{Bool, Int64} with 1144 stored entries:
⎡⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⠀⠀⠀⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⎤
⎢⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⠀⠀⠀⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⎥
⎢⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⠀⠀⠀⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⎥
⎢⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⠀⠀⠀⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⎥
⎢⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⠀⠀⠀⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⎥
⎢⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⠀⠀⠀⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⎥
⎢⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⠀⠀⠀⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⎥
⎢⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⠀⠀⠀⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⎥
⎢⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⠀⠀⠀⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⎥
⎢⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⠀⠀⠀⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⎥
⎢⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⠀⠀⠀⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⎥
⎢⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⠀⠀⠀⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⎥
⎢⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⠀⠀⠀⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⎥
⎢⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⠀⠀⠀⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⎥
⎣⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⠀⠀⠀⠘⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⠀⠀⠀⠃⠀⠀⠀⠀⠀⠀⠀⠀⎦
Another REPL option, credit to @jd-foster (this post):
using PrettyTables, TerminalPager
A = rand(150, 150);
A[A .< .1] .= NaN;
hl = TextHighlighter((d, i, j) -> isnan(d[i,j]), crayon"red")
io = IOContext(IOBuffer(), :color => true);
pretty_table(io, A, alignment=:r, display_size=(-1,-1), show_row_number_column=true, highlighters=[hl])
pager(String(take!(io.io)), frozen_columns=7, frozen_rows=3)