Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,143,290 members, 7,780,667 topics. Date: Thursday, 28 March 2024 at 07:01 PM

Coding For D Gurus:#challange - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Coding For D Gurus:#challange (1827 Views)

I Will Mentor/ Teach Coding For Free / Apply For Union Bank Campus Innovation Challange / Learn Coding For Free, With Microverse, Pay The Tuition When You Start Earning. (2) (3) (4)

(1) (Reply) (Go Down)

Coding For D Gurus:#challange by Nobody: 10:26pm On Apr 07, 2020
Firstly am not a guru bt if u r then am sure this challange shld be a breeze for you the challange is to write a program to manipulate a matrix it shld be able to do the following to a matrix:
1.Transpose a matrix:
Input: 1 2 3
4 5 6
7 8 9

Output:1 4 7
2 5 8
3 6 9
2. Find the dot product of a matrix:
Input: 1 2 3
4 5 6 *2
7 8 9

Output: 2 4 6
8 10 12
14 16 18
3. Create a Matrix:
Input:4*3
Output: 1 2 3 4
5 6 7 8
9 10 11 12

##################################
This challenge is for those who just love a bit of a challange nd the gurus who i hav been seeing dishing out some nice pice of algo. Not for money or any cash prize just for the joy of CODE
Enjoy
##################################
P.s after 3 days i will post the answer written in python bt it is still an algorithm so just follow it to understand python is kinda like pseude - code
###################################
Re: Coding For D Gurus:#challange by Nobody: 7:55pm On Apr 08, 2020
Is that no one tried or even attempted to solve it damn even if it wrong it is cool to try tor tommorrow i will be posting it.
Seems that majority only code for cash not for joy sadden take care
Re: Coding For D Gurus:#challange by Nobody: 5:32pm On Apr 09, 2020
#Firts we make a function called sizen that returns the cols and rows in a matrix a try and catch block is been put incase it is not a matrix that is been inputed
def Size(matrix):
row=len(matrix)-1
col=0
try:
for i in matrix[row]:
col+=1
except TypeError:
pass
row+=1
return row,col
#This function creates a matrix by the rows and cols inputted

def Create_Matrix(self,rows,cols):
matrix=[]
temp_num=0
for i in range(rows):
inner_list=[]
matrix.append(inner_list)
for i in matrix:
for num in range(cols):
i.append(temp_num)
temp_num+=1
return matrix
#This function transposes a matrix
def Trans_Matrix(self,mat):
row,col=Size(mat)
dummy_matrix=Create_Matrix(row,col)
for i in range(row):
for j in range(col):
dummy_matrix[j][i]=mat[i][j]
return dummy_matrix
Here are the codes i left one out just so that with this ones u guyz could pice it together to code the last one
Re: Coding For D Gurus:#challange by progeek37(m): 6:09pm On Apr 09, 2020
Lawren76:
#Firts we make a function called sizen that returns the cols and rows in a matrix a try and catch block is been put incase it is not a matrix that is been inputed
def Size(matrix):
row=len(matrix)-1
col=0
try:
for i in matrix[row]:
col+=1
except TypeError:
pass
row+=1
return row,col
#This function creates a matrix by the rows and cols inputted

def Create_Matrix(self,rows,cols):
matrix=[]
temp_num=0
for i in range(rows):
inner_list=[]
matrix.append(inner_list)
for i in matrix:
for num in range(cols):
i.append(temp_num)
temp_num+=1
return matrix
#This function transposes a matrix
def Trans_Matrix(self,mat):
row,col=Size(mat)
dummy_matrix=Create_Matrix(row,col)
for i in range(row):
for j in range(col):
dummy_matrix[j][i]=mat[i][j]
return dummy_matrix
Here are the codes i left one out just so that with this ones u guyz could pice it together to code the last one

Okay why not join my coding group to share your ideas there with other programmers?
There are actually many redundant lines of code in your solution. Maybe if you join my coding WhatsApp group you can see a more improved solution.
Re: Coding For D Gurus:#challange by Maskyy(m): 11:02pm On Apr 09, 2020
You want to be a programmer, developer, data scientists, designer and mobile dev with full guide and motoring with tasks.

Codefans is helping a budding techie person Like you. Join their community and get train.

Fill this form to get started

https://docs.google.com/forms/d/18cWuMdfV2fZ7ERJHRkwzpAmqaAwA-_W5R4cpE0zGeFw/edit?usp=drivesdk
Re: Coding For D Gurus:#challange by Nobody: 11:36pm On Apr 09, 2020
progeek37:


Okay why not join my coding group to share your ideas there with other programmers?
There are actually many redundant lines of code in your solution. Maybe if you join my coding WhatsApp group you can see a more improved solution.

Hmmm i will think abt it cos in d past some grps hav mess me up so currently solo bt ppl change
Re: Coding For D Gurus:#challange by Shepherdd(m): 10:08am On Apr 10, 2020
Lawren76:
Firstly am not a guru bt if u r then am sure this challange shld be a breeze for you the challange is to write a program to manipulate a matrix it shld be able to do the following to a matrix:
1.Transpose a matrix:
Input: 1 2 3
4 5 6
7 8 9

Output:1 4 7
2 5 8
3 6 9
2. Find the dot product of a matrix:
Input: 1 2 3
4 5 6 *2
7 8 9

Output: 2 4 6
8 10 12
14 16 18
3. Create a Matrix:
Input:4*3
Output: 1 2 3 4
5 6 7 8
9 10 11 12

##################################
This challenge is for those who just love a bit of a challange nd the gurus who i hav been seeing dishing out some nice pice of algo. Not for money or any cash prize just for the joy of CODE
Enjoy
##################################
P.s after 3 days i will post the answer written in python bt it is still an algorithm so just follow it to understand python is kinda like pseude - code
###################################

def transpose(array):
v = [list(map(lambda x: x[ix], array)) for ix in range(len(array[0]))]
return v

def dot(array, constant):
d = [[x * constant for x in val] for val in array]
return d

def create(size_tuple, placeholder):
# size_tuple (row * column) i.e create((4,3), 0)
v = [[placeholder for i in range(size_tuple[1])] for i in range(size_tuple[0])]
return v


Note that your matrix creation contains an error. Matrix size is (row x column) not (column x row). And no assertion and type checking is done n my code.
Re: Coding For D Gurus:#challange by Nobody: 11:08am On Apr 10, 2020
Shepherdd:


def transpose(array):
v = [list(map(lambda x: x[ix], array)) for ix in range(len(array[0]))]
return v

def dot(array, constant):
d = [[x * constant for x in val] for val in array]
return d

def create(size_tuple, placeholder):
# size_tuple (row * column) i.e create((4,3), 0)
v = [[placeholder for i in range(size_tuple[1])] for i in range(size_tuple[0])]
return v


Note that your matrix creation contains an error. Matrix size is (row x column) not (column x row). And no assertion and type checking is done n my code.

First of all am very happy u did it,secondly if u check it the program knows which come first i.e row then column

So urs don't have type checking it works that all i do first then i make it efficent next
Re: Coding For D Gurus:#challange by Shepherdd(m): 3:35pm On Apr 10, 2020
Lawren76:


First of all am very happy u did it,secondly if u check it the program knows which come first i.e row then column

So urs don't have type checking it works that all i do first then i make it efficent next


My bad. I made the comment based on the example and not on the actual code.....
Re: Coding For D Gurus:#challange by Nobody: 8:23pm On Apr 10, 2020
Shepherdd:


My bad. I made the comment based on the example and not on the actual code.....

No prob. Bro
Re: Coding For D Gurus:#challange by Nobody: 8:47pm On Apr 10, 2020
progeek37:


Okay why not join my coding group to share your ideas there with other programmers?
There are actually many redundant lines of code in your solution. Maybe if you join my coding WhatsApp group you can see a more improved solution.

Here my number for d grp 07013927220
Re: Coding For D Gurus:#challange by 2muchopoTBdope(m): 9:43pm On Apr 10, 2020
Lawren76:
Firstly am not a guru bt if u r then am sure this challange shld be a breeze for you the challange is to write a program to manipulate a matrix it shld be able to do the following to a matrix:
1.Transpose a matrix:
Input: 1 2 3
4 5 6
7 8 9

Output:1 4 7
2 5 8
3 6 9
2. Find the dot product of a matrix:
Input: 1 2 3
4 5 6 *2
7 8 9

Output: 2 4 6
8 10 12
14 16 18
3. Create a Matrix:
Input:4*3
Output: 1 2 3 4
5 6 7 8
9 10 11 12

##################################
This challenge is for those who just love a bit of a challange nd the gurus who i hav been seeing dishing out some nice pice of algo. Not for money or any cash prize just for the joy of CODE
Enjoy
##################################
P.s after 3 days i will post the answer written in python bt it is still an algorithm so just follow it to understand python is kinda like pseude - code
###################################

Can I do this with MATLAB??
Re: Coding For D Gurus:#challange by 2muchopoTBdope(m): 9:44pm On Apr 10, 2020
Lawren76:
Firstly am not a guru bt if u r then am sure this challange shld be a breeze for you the challange is to write a program to manipulate a matrix it shld be able to do the following to a matrix:
1.Transpose a matrix:
Input: 1 2 3
4 5 6
7 8 9

Output:1 4 7
2 5 8
3 6 9
2. Find the dot product of a matrix:
Input: 1 2 3
4 5 6 *2
7 8 9

Output: 2 4 6
8 10 12
14 16 18
3. Create a Matrix:
Input:4*3
Output: 1 2 3 4
5 6 7 8
9 10 11 12

##################################
This challenge is for those who just love a bit of a challange nd the gurus who i hav been seeing dishing out some nice pice of algo. Not for money or any cash prize just for the joy of CODE
Enjoy
##################################
P.s after 3 days i will post the answer written in python bt it is still an algorithm so just follow it to understand python is kinda like pseude - code
###################################

Should I do this with MATLAB Cos I understand that language better??
Re: Coding For D Gurus:#challange by Nobody: 7:23am On Apr 11, 2020
2muchopoTBdope:


Should I do this with MATLAB Cos I understand that language better??

Well it your choice which language to use cos python is kinda like pesudo code sontp understand the algorithm would be simple
Re: Coding For D Gurus:#challange by Nobody: 2:13pm On Apr 11, 2020
2muchopoTBdope:


Should I do this with MATLAB Cos I understand that language better??

If u want to cos it an algorithm just follow d algorithm nd code it
Re: Coding For D Gurus:#challange by nosagold(m): 4:10pm On Apr 11, 2020
Lawren76:
Firstly am not a guru bt if u r then am sure this challange shld be a breeze for you the challange is to write a program to manipulate a matrix it shld be able to do the following to a matrix:
1.Transpose a matrix:
Input: 1 2 3
4 5 6
7 8 9

Output:1 4 7
2 5 8
3 6 9
2. Find the dot product of a matrix:
Input: 1 2 3
4 5 6 *2
7 8 9

Output: 2 4 6
8 10 12
14 16 18
3. Create a Matrix:
Input:4*3
Output: 1 2 3 4
5 6 7 8
9 10 11 12

##################################
This challenge is for those who just love a bit of a challange nd the gurus who i hav been seeing dishing out some nice pice of algo. Not for money or any cash prize just for the joy of CODE
Enjoy
##################################
P.s after 3 days i will post the answer written in python bt it is still an algorithm so just follow it to understand python is kinda like pseude - code
###################################

#assuming each matrix takes the following format
matrix = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]


def transpose_matrix(matrix):
list = []
for row in range(len(matrix)):
ma = []
for item in range(len(matrix[row])):
ma.append(matrix[item][row])
list.append(ma)

return list

def dot_product(matrix, dot):
list = []
for row in range(len(matrix)):
ma = []
for item in range(len(matrix[row])):
ma.append(matrix[row][item] * dot)
list.append(ma)

return list

def create_matrix(rows, columns):
start = 0
list = []
for row in range(rows):
ma = []
for item in range(columns):
start += 1
ma.append(start)
list.append(ma)
return list
Re: Coding For D Gurus:#challange by nosagold(m): 4:13pm On Apr 11, 2020
nosagold:


#assuming each matrix takes the following format
matrix = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]


def transpose_matrix(matrix):
list = []
for row in range(len(matrix)):
ma = []
for item in range(len(matrix[row])):
ma.append(matrix[item][row])
list.append(ma)

return list

def dot_product(matrix, dot):
list = []
for row in range(len(matrix)):
ma = []
for item in range(len(matrix[row])):
ma.append(matrix[row][item] * 2)
list.append(ma)

return list

def create_matrix(rows, columns):
start = 0
list = []
for row in range(rows):
ma = []
for item in range(columns):
start += 1
ma.append(start)
list.append(ma)
return list

sorry about the indentation, somehow nairaland text editor keeps messing with it
Re: Coding For D Gurus:#challange by 2muchopoTBdope(m): 5:34pm On Apr 11, 2020
Lawren76:


If u want to cos it an algorithm just follow d algorithm nd code it

OK but MATLAB already has a function for transpose. There might be no need to create a code for it when there is a function for it already.
If u want, I could do it, snap and send to u.

1 Like

Re: Coding For D Gurus:#challange by Nobody: 9:21pm On Apr 11, 2020
2muchopoTBdope:


OK but MATLAB already has a function for transpose. There might be no need to create a code for it when there is a function for it already.
If u want, I could do it, snap and send to u.


In a way still do it cos me i did it in python nd python has numpy for matrix manipulation bt still did it to test my algorithm skills so consider it like a test to ascert how goodnyoubare at algorithms

1 Like

Re: Coding For D Gurus:#challange by Nobody: 9:25pm On Apr 11, 2020
nosagold:


#assuming each matrix takes the following format
matrix = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]


def transpose_matrix(matrix):
list = []
for row in range(len(matrix)):
ma = []
for item in range(len(matrix[row])):
ma.append(matrix[item][row])
list.append(ma)

return list

def dot_product(matrix, dot):
list = []
for row in range(len(matrix)):
ma = []
for item in range(len(matrix[row])):
ma.append(matrix[row][item] * 2)
list.append(ma)

return list

def create_matrix(rows, columns):
start = 0
list = []
for row in range(rows):
ma = []
for item in range(columns):
start += 1
ma.append(start)
list.append(ma)
return list


Nice try
Re: Coding For D Gurus:#challange by nosagold(m): 10:23pm On Apr 11, 2020
Lawren76:



Nice try

It does work. There's a shorter way though but this does work
Re: Coding For D Gurus:#challange by Nobody: 10:25pm On Apr 11, 2020
nosagold:


It does work. There's a shorter way though but this does work

I know that y i put nice meaning thumbs up
Re: Coding For D Gurus:#challange by Runningwater(m): 5:17am On Jun 15, 2020
Matrix A for example
A' would transpose the matrix A in Matlab ,similar to Octave but don't know of Scilab.
It's better using the right tools(s) for the right job after all it's about getting the job done most times. Info: Matlab sees everything as a matrix, hence the name MATrix LABoratory.
Anyway, for learning sake it's okay understanding the algorithm.

(1) (Reply)

How Can I Learn Programming Without Computer School. / Nairaland Programming Contest (8-Puzzle) / Visual Basic Help Pls. Other Languages Can Try Too

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 52
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.