Remove rows/columns from MatrixStore in OjAlgo - ojalgo

Is there any convenient and efficient way to remove rows (or columns) from SparseMatrix in ojAlgo? I was trying to retrieve RowView from my matrix and then copy rows that should remain element by element to new matrix but this is not very efficient method.

Doing the same thing but using the ElementView2D obtained from the nonzeros() method would be much more efficient.

Related

How do I create a list of non-repeating cells/numbers in Google Sheets?

Iā€™m trying to emulate Minesweeper in Google Sheets, and for this I want to create a second map adjacent to the first with all of the correct values already in it. To randomize bomb position, I need a list of random numbers or cells(cells would be preferable). However, I cannot figure out how to do this without ending up repeating numbers. The result would ideally be a vertical array of cell coordinates. Thank you!
Answer
The following formula should produce the result you desire:
=SORTN(FLATTEN(MAKEARRAY(10,10,LAMBDA(row,col,ADDRESS(row,col)))),20,,RANDARRAY(100),)
In =MAKEARRAY, change the first 10 to adjust how many rows to randomly choose from, or the second 10 to adjust how many columns to choose from. The value in =RANDARRAY must be equal to the product of the number of rows and the number of columns. (e.g. in the above example, 10*10=100).
Change the 20 to adjust how many randomly chosen values to return.
Explanation
=MAKEARRAY is used to generate an array of every possible row and column combination. It accepts a =LAMBDA, which in this case is just the =ADDRESS function. The first two arguments of =MAKEARRAY determine how large the array should be, which is why changing them adjusts how many rows/columns to randomly pick from.
Then, the result of =MAKEARRAY is squashed into a single column using the =FLATTEN formula.
Finally, the entire thing is sorted randomly using =SORTN combined with =RANDARRAY. =SORTN also limits the number of results that are returned dependent on its second argument, which is why changing it adjusts how many results are returned.
If you want information on how to "freeze" the value of =RANDARRAY so it doesn't recalculate each time you change something, check out this question by player0.
Functions used:
=MAKEARRAY
=LAMBDA
=ADDRESS
=FLATTEN
=SORTN
=RANDARRAY

Google Sheet: Transform a row of cells to a matrix of cells

Just wonder if there is a single (perhaps complex) formula that transforms a row of cells into a matrix of cells (defined by width)?
I suppose I can do it with App Script however I think a single formula would be a more elegant answer. Hope it can be done by simple combo of google sheets built-in formula.
Here's another way to do this.
=ARRAYFORMULA(LAMBDA(width,IFNA(HLOOKUP(SEQUENCE(CEILING(COLUMNS(B1:P1)/width),width),{SEQUENCE(1,COLUMNS(B1:P1));B1:P1},2,0)))(5))
It essentially creates a lookup table with the values in B1:P1 and their position and it uses that information to fill a nxm grid.
See WRAPROWS in Google Sheets to learn more about how it works.
You can do this, it takes the number of rows and columns you choose to make that array (r & c) to map through INDEX that row
=MAKEARRAY(4,4,LAMBDA(r,c,INDEX(1:1,(r-1)*4+c)))

Rotate multiple data from many rows and combine them into one column

I have a certain type of data :
As we can see, I have many rows of the same size of cells in them (4) and the number of columns change accordingly to how much data I input.
What I would like to end up with, is something like this :
Either of this version works for me, so simply put I would need to use something similar to the =TRANSPOSE() function which flips the rows 90 degrees and then somehow combine the data from all the columns into one column. Any ideas?
EDIT ^ Above problem is resolved but I got another issue.
Now I would need to make something like this:
I would need to FLATTEN() the size1_x parts and then "copy" information on the left and on the right of that row to the flattened version of the table.
The expected outcome would need to be like this :
Use FLATTEN function:
=FLATTEN(B2:E5)
or
=FILTER(FLATTEN(B2:E5),FLATTEN(B2:E5)<>"")
if you don't want blanks

How to calculate Dimensions from a Text String in a single cell?

I am need to calculate the dimensions from cell values that are entered as strings into a single cell vs. 3 separate cells and I do not want to break the dimensions into Length (L) x Width (W) x Height (H) Columns.. instead I am hoping there is a relatively simple function that would allow me to calculate the total cubic dimensions from that single cell.
I am aware of this tutorial that can take a string and be used to break it into 3 separate cells.. but that defeats the point of what I am trying to do.
My data looks like this:
Dimensions
Cub/In.
CF
70x13x13
11830
6.85
24*18*13
5616
3.25
24x16x12
16x24x10
Right now the data is entered as either "LxWxH" or "L*W*H" in that text formant and the columns that have values like the 5616 above are me manually re-entering "=24*18*13".. literally one character difference.
I did try a CONCATENATE to just append an "=" to the beginning but got errors on all in Google Sheets (for comparison) or a Literal string into processed as a formula in Excel.
=CONCATENATE(ā€œ=ā€,B1)
Looking for a simple way to do this calculation in a single column and being able to have to enter the data once or utilize the existing data. I don't mind doing a single bulk replace of "x" to "*" on the input column to standardize the source column but don't want to have to do a series of bulk replaces every time I want to run through the data.
Thoughts?
Use SUBSTITUTE to get them all to the same, then use SPLIT and wrap in PRODUCT:
=PRODUCT(SPLIT(SUBSTITUTE(A2,"*","x"),"x"))
Or shorter Version shown by #JvdV:
=PRODUCT(SPLIT(A2,"*x"))

Improving a Spreadsheet Formula to be more dynamic

I have a a couple sheets that I want to filter the values of and sum them together. I have a working function:
=SUM(INDEX(Grades!M32:V32,0,B2)+INDEX(Grades!M32:V32,0,C2)+INDEX(Grades!M32:V32,0,D2)+INDEX(Grades!M32:V32,0,E2)+INDEX(Grades!M32:V32,0,F2)+INDEX(Grades!M32:V32,0,G2))
and this is working fine. The problem is it isn't really dynamic and I was wondering if there was a more efficient way to approach this instead of using so many Indexes.
Index is grabbing a horizontal range of numbers from another sheet and getting the needed index position from a small table in another sheet.
Update
I was able to get the formula working how I wanted by inserting an IF statement that would not do the VLOOKUP if one of the cells was empty.
=ArrayFormula(SUM(IF(B2:I2 <> "",VLOOKUP(1,{1,Grades!$M$32:$V$32},B2:I2+1))))
It looks a bit strange, but this is one way:
=ArrayFormula(SUM(VLOOKUP(1,{1,Grades!M32:V32},B2:G2+1,0)))
In the VLOOKUP, 1 is the value you are searching for, {1,Grades!M32:V32} is the array in which you are searching, B2:G2+1 is the column index (or rather, indices) you wish to return, and 0 dictates that you require an exact match.
{1,Grades!M32:V32} constructs a horizontal, one-row array that has 1 in the left-most element, with the values in Grades!M32:V32 to the right of it.
VLOOKUP will search down the left-most column of that array. It will always "find" the 1 that it is searching for in the left-most column, because we have purposely manufactured that.
Where the action really happens is in the third argument, where we return the columns in that manufactured array corresponding with the values in B2:G2 (I should add, I assumed that all cells in B2:G2 are populated - it will return the wrong result if any are blank). The +1 is to account for the extra element (the 1) we tacked on to the left of the lookup array.

Resources