Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion. Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 Doom9's Forum Row and column given the position?
 User Name Remember Me? Password
 Register FAQ Calendar Search Today's Posts Mark Forums Read

 Thread Tools Search this Thread Display Modes
 12th September 2022, 17:25 #1  |  Link Asmodian Registered User   Join Date: Feb 2002 Location: San Jose, California Posts: 4,419 Row and column given the position? Code: `Chemical.Row = int((i-i%cols)/cols+1) if i%cols > 0 else int((i-i%cols)/cols)` Is there a better way to get the row and column given the position? I have been using this method for years, but it has always felt like there should be a simpler way to do it. __________________ madVR options explained
 12th September 2022, 23:05 #2  |  Link LoRd_MuldeR Software Developer     Join Date: Jun 2005 Location: Last House on Slunk Street Posts: 13,250 Assuming row-major order as well as zero-based indexing: Code: ```row_index = address / num_columns; /* integer division (truncating) */ col_index = address % num_columns; /* modulo operation */``` __________________ Go to https://standforukraine.com/ to find legitimate Ukrainian Charities 🇺🇦✊ Last edited by LoRd_MuldeR; 12th September 2022 at 23:14.
13th September 2022, 00:05   #3  |  Link
StainlessS
HeartlessS Usurer

Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,981
Quote:
 Originally Posted by LoRd_MuldeR Assuming row-major order as well as zero-based indexing: Code: ```row_index = address / num_columns; /* integer division (truncating) */ col_index = address % num_columns; /* modulo operation */```
I think he's wanting Python solution,

So assuming address and num_columns both +ve integer, AND zero-based indexing, maybe just
Code:
```row_index = address // num_columns
col_index = address %  num_columns```
AFTER HERE is just me Waffling

Easier {for me} to do in C or even Avisynth script than in Python [I dont speak Python].

On looking at OP, I was not sure if was written to also cope with -ve address AND array subscript results [end relative or something, seemed overly complicated].

From here[Learn X in Y minutes<Python>]:- https://learnxinyminutes.com/docs/python/

Quote:
 # Math is what you would expect 1 + 1 # => 2 8 - 1 # => 7 10 * 2 # => 20 35 / 5 # => 7.0 # Integer division rounds down for both positive and negative numbers. 5 // 3 # => 1 -5 // 3 # => -2 5.0 // 3.0 # => 1.0 # works on floats too -5.0 // 3.0 # => -2.0 # The result of division is always a float 10.0 / 3 # => 3.3333333333333335 # EDIT: I think that means also 10 / 3 => 3.3333333333333335 # Modulo operation 7 % 3 # => 1 # i % j have the same sign as j, unlike C -7 % 3 # => 2
EDIT:
Code:
```# Avisynth Script
blankclip
Subtitle(String(  -7 / 3  ),size=48)        # result = -2
Subtitle(String(  -7 % 3  ),Y=100,size=48)  # result = -1 : ie  (-2*3) + -1 => -7
return last

# I think Python -7 // 3 => -3
# I think Python -7  % 3 =>  2 : ie, (-3*3) + 2 => -7```
EDIT:
Quote:
 On looking at OP, I was not sure if was written to also cope with -ve address AND array subscript results [end relative or something, seemed overly complicated].
From Python X in Y minutes thingy
Quote:
 # li is now [1, 2, 4, 3] again. # Access a list like you would any array li[0] # => 1 # Look at the last element li[-1] # => 3
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 13th September 2022 at 03:38.

 Thread Tools Search this Thread Search this Thread: Advanced Search Display Modes Hybrid Mode

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home Announcements and Chat     General Discussion     News     Forum / Site Suggestions & Help General     Decrypting     Newbies     DVD2AVI / DGIndex     Audio encoding     Subtitles     Linux, Mac OS X, & Co Capturing and Editing Video     Avisynth Usage     Avisynth Development     VapourSynth     Capturing Video     DV     HDTV / DVB / TiVo     NLE - Non Linear Editing     VirtualDub, VDubMod & AviDemux     New and alternative a/v containers Video Encoding     (Auto) Gordian Knot     MPEG-4 ASP     MPEG-4 Encoder GUIs     MPEG-4 AVC / H.264     High Efficiency Video Coding (HEVC)     New and alternative video codecs     MPEG-2 Encoding     VP9 and AV1 (HD) DVD, Blu-ray & (S)VCD     One click suites for DVD backup and DVD creation     DVD & BD Rebuilder     (HD) DVD & Blu-ray authoring     Advanced authoring     IFO/VOB Editors     DVD burning Hardware & Software     Software players     Hardware players     PC Hard & Software Programming and Hacking     Development     Translations

All times are GMT +1. The time now is 11:05.

 doom9.org - Archive - Top