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, 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: 4 months ago.

Category: Programming

Share this conversation

Customer:replied 4 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 4 months ago.

I have also a padded matrix that makes it square and all padded values are 'nAn'

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 4 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 4 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?

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.

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

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

Computer Software Engineer

Satisfied Customers:

7260

MS in IT.Several years of programming experience in Java C++ C C# Python VB Javascript HTML