How JustAnswer Works:

  • Ask an Expert
    Experts are full of valuable knowledge and are ready to help with any question. Credentials confirmed by a Fortune 500 verification firm.
  • Get a Professional Answer
    Via email, text message, or notification as you wait on our site.
    Ask follow up questions if you need to.
  • 100% Satisfaction Guarantee
    Rate the answer you receive.

Ask Zabo04 Your Own Question

Zabo04
Zabo04, Programming Enthusiast
Category: Programming
Satisfied Customers: 283
Experience:  C/C++, python, perl, excel, matlab/octave, java, and R experience. Genetic algorithm, vision, GUIs.
58597962
Type Your Programming Question Here...
Zabo04 is online now

Can you help with Python i.e. resolving some queries where

Resolved Question:

can you help with Python i.e. resolving some queries where conditional statements are not working as I planned?
Submitted: 6 months ago.
Category: Programming
Customer: replied 6 months ago.
Hi. I have a non square matrix where each row contains a range of different numbers. How do I get Python to iterate through these rows to pick the smallest number in each row. Also, I have a vector of random numbers i.e [2,4,5,6,7,4,6,3] and these show which row in the matrix I want the process to iterate to. i.e the first iteration will be on row 2 and will find the smallest number. The next iteration will be on row 4 to find the smallest number. Also, so for example there are two instance where the 6th row is to be iterated. How do I get it to only ever use a value once in each row. I.e find the smallest number in the first iteration on row 6 then find the second smallest number in the next iteration over row 6?
Customer: replied 6 months ago.
I have also a padded matrix that makes it square and all padded values are 'nAn'
Expert:  Zabo04 replied 6 months ago.

I am working on your question now and I should have something in a little bit that serves as an example.

Customer: replied 6 months ago.
Hi, thanks. If it helps it is an algorithm of the greedy nature but It to eliminate certain elements once they have already been used
Expert:  Zabo04 replied 6 months ago.

Just use and replace with NaN.

Customer: replied 6 months ago.
Oh OK thanks. What is the time scale on your example being ready?
Expert:  Zabo04 replied 6 months ago.

Numpy isn't installing on my windows box, so I have to find another way to solve the problem.

Expert:  Zabo04 replied 6 months ago.

Try this out and let me know how it works for you. I had to name the file .txt to attach it, but just change the extension to .py and run.

Customer: replied 6 months ago.
Thanks this seems to work. One question, how do I define my own matrix i.e not random values but type out my own matrix?
Customer: replied 6 months ago.
Sorry, I have defined my own matrix now. I have a matrix ([[1,2,3,4,5,6,7,8,9],[1,2,4,7,2,4,5,6,34],[3,4,6,1,7,88,2,5,4],[4,8,67,45,55,2,9,5,9]]) and search vector [2, 2, 3, 2, 0] and im getting wrong results:Row 2
[3, 4, 6, nan, 7, 88, 2, 5, 4]
Min: 1Row 2
[3, 4, 6, nan, 7, 88, 2, 5, 4]
Min: 2Row 3
[4, 8, 67, 45, 55, 2, 9, 5, 9]
Min: 2Row 2
[3, 4, 6, nan, 7, 88, 2, 5, 4]
Min: 2 <------- This should not be 2. The 2 should have been replaced with nan and min should be 3Row 0
[nan, 2, 3, 4, 5, 6, 7, 8, 9]
Min: 1
Customer: replied 6 months ago.
Sorry for all the questions. I have another one. How would I set all values to 0 in the column that the found value is in. i.e if the minimum value is in column 20, how do i then set all values in column 20 to 0?
Expert:  Zabo04 replied 6 months ago.

Let me look at this. Sorry for the delayed response, I'm in the US on the east coast and I had to call it a night so I could get some sleep.

Expert:  Zabo04 replied 6 months ago.

Okay, I think I answered all of your questions. I updated the comments in the python code, defined your matrix, replaced the column for the minimum value with 0 in all rows. I added printing the updated matrix so that you can see the 0s. I also changed the min function and included a filter argument so it will find the minimum value greater than 0, that why once you have a match when you replace the column values for the match with a 0. I also moved where the row is printed, so instead of seeing the 0 or NaN that was replaced, it shows the row so you can verify it found the minimum value, and then it prints the whole matrix to show the column replacements. Ask more questions if you have them. I attached the file with a .txt again, JustAnswer filters file types and .py is not allowed neither is .cpp or .c or .h or .m, it just gets annoying sometimes.

I think the none NaN replacement the second time was the equality operator on NaN. NaN is nothing so it both is equal and not equal. I have python 2.7.12, which is better, but NaN is still a newer concept to the language, relatively. Numpy handles it, but then you have to have numpy, and it really is better to solve in the base language if possible so that it is more portable and has fewer dependencies. Using 0s and a filter works better and is what you want anyways. Thanks for working with me.

Zabo04, Programming Enthusiast
Category: Programming
Satisfied Customers: 283
Experience: C/C++, python, perl, excel, matlab/octave, java, and R experience. Genetic algorithm, vision, GUIs.
Zabo04 and 2 other Programming Specialists are ready to help you
Customer: replied 6 months ago.
Thanks so much for all your help :)
Expert:  Zabo04 replied 6 months ago.

Anytime, glad I was able to help you with your question.

What Customers are Saying:

 
 
 
  • My Expert answered my question promptly and he resolved the issue totally. This is a great service. I am so glad I found it I will definitely use the service again if needed. One Happy Customer
< Previous | Next >
  • My Expert answered my question promptly and he resolved the issue totally. This is a great service. I am so glad I found it I will definitely use the service again if needed. One Happy Customer
  • Wonderful service, prompt, efficient, and accurate. Couldn't have asked for more. I cannot thank you enough for your help. Mary C.
  • This expert is wonderful. They truly know what they are talking about, and they actually care about you. They really helped put my nerves at ease. Thank you so much!!!! Alex
  • Thank you for all your help. It is nice to know that this service is here for people like myself, who need answers fast and are not sure who to consult. GP
  • I couldn't be more satisfied! This is the site I will always come to when I need a second opinion. Justin
  • Just let me say that this encounter has been entirely professional and most helpful. I liked that I could ask additional questions and get answered in a very short turn around. Esther
  • Wonderful service, prompt, efficient, and accurate. Couldn't have asked for more. I cannot thank you enough for your help. Mary C.
 
 
 

Meet The Experts:

 
 
 
  • ATLPROG

    ATLPROG

    Computer Software Engineer

    Satisfied Customers:

    7260
    MS in IT.Several years of programming experience in Java C++ C C# Python VB Javascript HTML
< Previous | Next >
  • http://ww2.justanswer.com/uploads/SP/spatlanta2010/2011-6-23_12450_photo.64x64.gif ATLPROG's Avatar

    ATLPROG

    Computer Software Engineer

    Satisfied Customers:

    7260
    MS in IT.Several years of programming experience in Java C++ C C# Python VB Javascript HTML
  • http://ww2.justanswer.com/uploads/ComputersGuru/2010-02-13_051118_Photo41.JPG LogicPro's Avatar

    LogicPro

    Computer Software Engineer

    Satisfied Customers:

    5514
    Expert in C, C++, Java, DOT NET, Python, HTML, Javascript, Design.
  • http://ww2.justanswer.com/uploads/lifesaver333/2010-10-17_191349_ls.jpeg lifesaver's Avatar

    lifesaver

    Computer Software Engineer

    Satisfied Customers:

    936
    Several years of intensive programming and application development experience in various platforms.
  • http://ww2.justanswer.com/uploads/EH/ehabtutor/2012-8-2_202016_1.64x64.jpg ehabtutor's Avatar

    ehabtutor

    Computer Software Engineer

    Satisfied Customers:

    766
    Bachelor of computer science, 5+ years experience in software development, software company owner
  • http://ww2.justanswer.com/uploads/eljonis/2010-01-06_130406_eljon2.jpg Eljon's Avatar

    Eljon

    Consultant

    Satisfied Customers:

    558
    Founder of StockCanvas.com
  • http://ww2.justanswer.com/uploads/FA/fael/2011-1-15_104041_profile500x500.64x64.jpg Rafael Martins's Avatar

    Rafael Martins

    Computer Software Engineer

    Satisfied Customers:

    446
    Desktop, Mobile and Web Developer. 7+ years of experience. Creative solutions provider.
  • http://ww2.justanswer.com/uploads/CH/chutz747/2011-11-6_14231_me.64x64.jpg The-PC-Guy's Avatar

    The-PC-Guy

    Software Engineer

    Satisfied Customers:

    320
    Extensive Knowledge in PHP, MYSQL, CSS & Javascript