Array ,extract all index 2 elments

A forum for general discussion of the Python programming language.

Array ,extract all index 2 elments

Postby giny28 » Tue Jan 07, 2014 7:11 pm

Hello,

I would like to encode a column2 () function which allows to extract all index M 2 elements , and must then generalize a
column () function to any column of a matrix of n rows by m columns . " I must use python langage and i am a bigginer in python :roll:

The objective is to extract the index or index elements 2 of each row 2 eg 3 , 6 .... .
But col2 () function will it be binary ? 2 arguments: the matrix and the index.
You must use 2 loops ... well I think!

Already for encoding an array of n rows by m columns, eg matrix (2,3) gives [ [ 1 , 2, 3 ] , [ 4 , 5, 6 ] ] .
Code: Select all
>>> def matrix (line, col):
    m = [ ]
    for e in range ( line):
        z = [ ]
        for o in range ( col):
            z + = [ 3 * e + o + 1]
        m + = [z]
    return m


_ Also, I can't use the append () method :cry: , append is supposed to add an item to the end of such a list:

I know, I didn't use the append () method to the code PX10 -1, but I found something interesting :

Code: Select all
   >>> m = []
     m.append >>> (range (3) )
     m.append >>> (range (3, 6)
     m.append >>> (range (6, 9) )

     >>>m
     [ [0 , 1, 2 ], [3 , 4, 5 ], [6 , 7, 8 ] ] # there, it starts at 0 , but in my case here must begin with 1.



Thank you in advance! :P
Last edited by stranac on Tue Jan 07, 2014 7:21 pm, edited 1 time in total.
Reason: First post lock.
giny28
 
Posts: 4
Joined: Tue Jan 07, 2014 7:02 pm

Re: Array ,extract all index 2 elments

Postby ochichinyezaboombwa » Tue Jan 07, 2014 8:09 pm

What have you tried? show your effort.

I assume the matrix() function is not defined by you; however it uses list comprehension: do you know anything about it? if yes it's one line to write a function
col_n(m, n) that would do what's required.
ochichinyezaboombwa
 
Posts: 200
Joined: Tue Jun 04, 2013 7:53 pm

Re: Array ,extract all index 2 elments

Postby giny28 » Tue Jan 07, 2014 9:42 pm

I have done the two codes for the fonction matrix and append(), it's an exercice for practice, but i failed many times to make a correct code for the last .Perhaps , tomorrow , i will make a better one :geek:
An arrow is a group of list , but the matter is to extract elements preciasily from a column ...
Anyway , thanks for your help ! (ofcourse , it's a binary function , i already know it :mrgreen: )
giny28
 
Posts: 4
Joined: Tue Jan 07, 2014 7:02 pm

Re: Array ,extract all index 2 elments

Postby ochichinyezaboombwa » Tue Jan 07, 2014 10:15 pm

Please read this before posting more.
In general, the rule here is: no code from you == no help from us.
Also, I have no idea what do you call a "binary function"?
ochichinyezaboombwa
 
Posts: 200
Joined: Tue Jun 04, 2013 7:53 pm

Re: Array ,extract all index 2 elments

Postby workhorse » Tue Jan 21, 2014 7:23 am

I think he means the function takes two arguments, thats all.
workhorse
 
Posts: 5
Joined: Mon Jan 13, 2014 10:35 pm

Re: Array ,extract all index 2 elments

Postby giny28 » Tue Jan 21, 2014 7:38 pm

Anyway , thanks for your help , i found the solution :mrgreen:
giny28
 
Posts: 4
Joined: Tue Jan 07, 2014 7:02 pm


Return to General Discussions

Who is online

Users browsing this forum: Google [Bot] and 3 guests

cron