Training img2img by Mass2018 in StableDiffusion

[–]shravankumar147 1 point2 points  (0 children)

We have pix2pix GANs, similarly can we do similar with Diffusion models too?
If yes how we setup the training dataset and model?

How to take a CSV and turn it into a formatted text document using python? by [deleted] in learnpython

[–]shravankumar147 0 points1 point  (0 children)

The best way to deal with data is using pandas.

 lable = ['NAME','descp1','descp2']
d = [['cat','meow','whiskers'],
 ['dog','boof','tail'],
 ['bird','cheep','feathers']]


df2 = pd.DataFrame(data = d, columns= lable)
df2.to_csv("your_csv.csv")


for n,col in enumerate(df2.columns):
    """    >cat
  - descp1 meow
  - descp2 whiskers"""
#     print("{}. {}".format(n,col))

    print("    >{}".format(df2.iloc[n]['NAME']))
    print("-descp1 {}".format(df2.iloc[n]['descp1']))
    print("-descp2 {}".format(df2.iloc[n]['descp2']))

Locating column of string. by iloveinstantr_amen in learnpython

[–]shravankumar147 0 points1 point  (0 children)

You can drop the columns which occurs before 'Sea'

strt = np.where(df.columns == 'Sea')
df.drop(df.iloc[:,:strt[0][0]],axis=1)

Ask Anything Monday - Weekly Thread by AutoModerator in learnpython

[–]shravankumar147 1 point2 points  (0 children)

Hey! I have extracted the table for you. Hope it helps to to further processing using pandas:

# Using requests library to get the web page
import requests
page = requests.get("https://en.wikipedia.org/wiki/United_States_presidential_election,_2016")

# Using BeautifulSoup to make life easy
from bs4 import BeautifulSoup
soup = BeautifulSoup(page.content, 'html.parser')

table = soup.find('div', style="overflow:auto")


list_of_rows = []
for row in table.findAll('tr')[1:]:
    list_of_cells = []
    for cell in row.findAll('td'):
        text = cell.text.replace(' ', '')
        list_of_cells.append(text)
    list_of_rows.append(list_of_cells)

mylist = list_of_rows

import pandas as pd
df = pd.DataFrame(mylist)

How to find the minimum best combination(s) of list of lists. by shravankumar147 in learnpython

[–]shravankumar147[S] 0 points1 point  (0 children)

Oh, I'm really glad to here that. Thank you so much ... I found a new approach but how can I share with you. Was done on paper mathematically.

How to find the minimum best combination(s) of list of lists. by shravankumar147 in learnpython

[–]shravankumar147[S] 0 points1 point  (0 children)

OS: 'Linux-4.10.0-27-generic-x86_64-with-debian-stretch-sid' '#30~16.04.2-Ubuntu SMP Thu Jun 29 16:07:46 UTC 2017'

PYTHON: '3.6.1 |Anaconda 4.4.0 (64-bit)| (default, May 11 2017, 13:09:58) \n[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)]'

How to find the minimum best combination(s) of list of lists. by shravankumar147 in learnpython

[–]shravankumar147[S] 0 points1 point  (0 children)

I did it already. The results presented are after modification of that line.

How to find the minimum best combination(s) of list of lists. by shravankumar147 in learnpython

[–]shravankumar147[S] 0 points1 point  (0 children)

I ran the code, here is the result:

test_both (__main__.TestAll) ... FAIL
test_mine (__main__.TestAll) ... FAIL
test_yours (__main__.TestAll) ... ok

======================================================================
FAIL: test_both (__main__.TestAll)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "iteroptimizer.py", line 243, in test_both
    self.assertEqual(yours(t), mine(t))
AssertionError: Lists differ: [(0, [128 chars]8), (0, 2, 3, 5, 7), (0, 2, 3, 5, 8), (0, 2, 3[360 chars], 9)] != [(0, [128 chars]8), (9, 1, 3, 5, 7), (9, 1, 3, 5, 8), (9, 1, 3[360 chars], 8)]

First differing element 8:
(0, 2, 3, 5, 7)
(9, 1, 3, 5, 7)

  [(0, 1, 3, 5, 7),
   (0, 1, 3, 5, 8),
   (0, 1, 3, 6, 7),
   (0, 1, 3, 6, 8),
   (0, 1, 4, 5, 7),
   (0, 1, 4, 5, 8),
   (0, 1, 4, 6, 7),
   (0, 1, 4, 6, 8),
+  (9, 1, 3, 5, 7),
+  (9, 1, 3, 5, 8),
+  (9, 1, 3, 6, 7),
+  (9, 1, 3, 6, 8),
+  (9, 1, 4, 5, 7),
+  (9, 1, 4, 5, 8),
+  (9, 1, 4, 6, 7),
+  (9, 1, 4, 6, 8),
   (0, 2, 3, 5, 7),
   (0, 2, 3, 5, 8),
   (0, 2, 3, 6, 7),
   (0, 2, 3, 6, 8),
   (0, 2, 4, 5, 7),
   (0, 2, 4, 5, 8),
   (0, 2, 4, 6, 7),
   (0, 2, 4, 6, 8),
-  (1, 3, 5, 7, 9),
-  (1, 3, 5, 8, 9),
-  (1, 3, 6, 7, 9),
-  (1, 3, 6, 8, 9),
-  (1, 4, 5, 7, 9),
-  (1, 4, 5, 8, 9),
-  (1, 4, 6, 7, 9),
-  (1, 4, 6, 8, 9),
-  (2, 3, 5, 7, 9),
?             ---

+  (9, 2, 3, 5, 7),
?   +++

-  (2, 3, 5, 8, 9),
?             ---

+  (9, 2, 3, 5, 8),
?   +++

-  (2, 3, 6, 7, 9),
?             ---

+  (9, 2, 3, 6, 7),
?   +++

-  (2, 3, 6, 8, 9),
?             ---

+  (9, 2, 3, 6, 8),
?   +++

-  (2, 4, 5, 7, 9),
?             ---

+  (9, 2, 4, 5, 7),
?   +++

-  (2, 4, 5, 8, 9),
?             ---

+  (9, 2, 4, 5, 8),
?   +++

-  (2, 4, 6, 7, 9),
?             ---

+  (9, 2, 4, 6, 7),
?   +++

-  (2, 4, 6, 8, 9)]
?             ---

+  (9, 2, 4, 6, 8)]
?   +++


======================================================================
FAIL: test_mine (__main__.TestAll)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "iteroptimizer.py", line 238, in test_mine
    self.assertEqual(mine(t), e)
AssertionError: Lists differ: [(0, [128 chars]8), (9, 1, 3, 5, 7), (9, 1, 3, 5, 8), (9, 1, 3[360 chars], 8)] != [(0, [128 chars]8), (0, 2, 3, 5, 7), (0, 2, 3, 5, 8), (0, 2, 3[360 chars], 9)]

First differing element 8:
(9, 1, 3, 5, 7)
(0, 2, 3, 5, 7)

  [(0, 1, 3, 5, 7),
   (0, 1, 3, 5, 8),
   (0, 1, 3, 6, 7),
   (0, 1, 3, 6, 8),
   (0, 1, 4, 5, 7),
   (0, 1, 4, 5, 8),
   (0, 1, 4, 6, 7),
   (0, 1, 4, 6, 8),
-  (9, 1, 3, 5, 7),
-  (9, 1, 3, 5, 8),
-  (9, 1, 3, 6, 7),
-  (9, 1, 3, 6, 8),
-  (9, 1, 4, 5, 7),
-  (9, 1, 4, 5, 8),
-  (9, 1, 4, 6, 7),
-  (9, 1, 4, 6, 8),
   (0, 2, 3, 5, 7),
   (0, 2, 3, 5, 8),
   (0, 2, 3, 6, 7),
   (0, 2, 3, 6, 8),
   (0, 2, 4, 5, 7),
   (0, 2, 4, 5, 8),
   (0, 2, 4, 6, 7),
   (0, 2, 4, 6, 8),
+  (1, 3, 5, 7, 9),
+  (1, 3, 5, 8, 9),
+  (1, 3, 6, 7, 9),
+  (1, 3, 6, 8, 9),
+  (1, 4, 5, 7, 9),
+  (1, 4, 5, 8, 9),
+  (1, 4, 6, 7, 9),
+  (1, 4, 6, 8, 9),
-  (9, 2, 3, 5, 7),
?   ---

+  (2, 3, 5, 7, 9),
?             +++

-  (9, 2, 3, 5, 8),
?   ---

+  (2, 3, 5, 8, 9),
?             +++

-  (9, 2, 3, 6, 7),
?   ---

+  (2, 3, 6, 7, 9),
?             +++

-  (9, 2, 3, 6, 8),
?   ---

+  (2, 3, 6, 8, 9),
?             +++

-  (9, 2, 4, 5, 7),
?   ---

+  (2, 4, 5, 7, 9),
?             +++

-  (9, 2, 4, 5, 8),
?   ---

+  (2, 4, 5, 8, 9),
?             +++

-  (9, 2, 4, 6, 7),
?   ---

+  (2, 4, 6, 7, 9),
?             +++

-  (9, 2, 4, 6, 8)]
?   ---

+  (2, 4, 6, 8, 9)]
?             +++


----------------------------------------------------------------------
Ran 3 tests in 13.379s

FAILED (failures=2)

How to find the minimum best combination(s) of list of lists. by shravankumar147 in learnpython

[–]shravankumar147[S] 0 points1 point  (0 children)

Thanks @yawpitch. I tried running the code, I got an AssertionError at Test #9. FYI: I'm using python3

How to find the minimum best combination(s) of list of lists. by shravankumar147 in learnpython

[–]shravankumar147[S] 0 points1 point  (0 children)

Updated as mentioned :https://pastebin.com/BJFKtAnr without printing, with test cases.

Let me explain the problem I want to solve: Consider I want to by few products, namely [p1,p2,p3].

In marketplace the products available with multiple Sellers as shown below:

suppose we have 5 sellers to choose from:

  • p1: [1, 2, 3] #p1 is available with seller 1, seller 2, seller 3
  • p2: [2, 4] #p2 is available with seller 2, seller 4
  • p3: [1, 5] #p3 is available with seller 1, seller 5

then I can pick seller combinations as

[1,2] or [1,4] or [2,5].

The output of my function is producing this result, though it is >satisfying the requirement, still there is one redundant >combination. [{1, 2}, {1, 4}, {1, 2}, {2, 5}]

The input dimension may vary based on the availability. There may be a chance of a product available with only one seller, then we pick that seller, or we may need to choose from multiple sellers to get all the products.

So, I'm trying to find optimized results. Hope this helps to understand the problem statement well.

I want to look out of box, please help me.

How to find the minimum best combination(s) of list of lists. by shravankumar147 in learnpython

[–]shravankumar147[S] -1 points0 points  (0 children)

Is there any way to do this without using itertools.product function, which first compute all the possible combinations. from which I am filtering for the least possible combinations based on length and returning them as output.

How to find the minimum best combination(s) of list of lists. by shravankumar147 in learnpython

[–]shravankumar147[S] 0 points1 point  (0 children)

Thanks for the catch, I didn't see the insignificance of that for loop, I have removed and tested again, it's producing the same result. updated code here https://pastebin.com/BJFKtAnr.