Jump to content

Computer Science

  1. Hi, I am trying to create an integer 2D array. I have used numpy, but it creates a floating point array. When I am printing this 8 * 8 array, its printing each entry of 8*8 array in a separate line. I want to print each row on a new line import numpy as np class Board: Matrix = np.empty((8, 8)) Matrix.fill(0) def __init__(self, n): self.n = n def displayBDMatrix(self, n): for i in range(n): for j in range(n): print(Board.Matrix[i][j]), def main(self): n=8 #self.display(n) self.displayBDMatrix(n) #self.displayPieces() if __name__ == "__main__": objBoard = Board…

    • 0

      Reputation Points

    • 4 replies
    • 1.2k views
  2. Started by zak100,

    Hi, I am trying to execute the following algorithm shown in the image. I am trying to get the table shown in the image: 1st Iteration L2: 1:CS=A, SL = A, NSL = A L3: while NSL!=[]: true L4: L6:no children: false L17:NSL =BCDA L18:CS:=B L19:SL=BA L20, L21 2nd Iteration L3:While NSL (true) L4: L6:no children: false L17: NSL=EFBCDA L18: CS:=E L19:SL:= EBA L20, L21 3rd Iteration L3:while NSL (true) L4: L6:no children: false L17:NSL= HIEFBCDA L18: CS:= H L19:SL:=HEBA L20, L21 At this point its fine but when there are no more children of current node, it has to backtrack, so it should execute the w…

    • 0

      Reputation Points

    • 1 reply
    • 1.4k views
  3. Started by zak100,

    import numpy as np class CPieces: pieceIndex=0; def __init__(self, pieceIndex): if (pieceIndex<8): self.pieceIndex = pieceIndex else: self.pieceIndex = pieceIndex class B: Matrix = np.empty((8, 8)) Matrix.fill(0) def __init__(self, n): self.n=n CPieces.pieces = []#no error if commented for i in range(n): #no error if commented CPieces.pieces.append = CPieces(self, i)#no error if commented def display(self, n): print(n) def main(self): n=8 self.display(n) if __name__ == "__main__": objB = B(8) objB.main() Hi, Following is the output. If I …

    • 0

      Reputation Points

    • 1 reply
    • 803 views
  4. Started by zak100,

    Hi, The above DFA has 3 final states: q0, q1 and q3 and q0 as its start state. It accepts strings: b, ba, bab, baba. Somebody please guide me whether it accepts aa or bb as a substring?I think it accepts string: abbaa. I want to create a DFA which does not accept aa and bb as substrings. Zulfi. Similalry the following one: I think this one does not accept aa and bb but its not correct because it does not accept any string. Somebody please guide me. Zulfi.

    • 0

      Reputation Points

    • 13 replies
    • 1.9k views
    • 1 follower
  5. Started by kaiserh,

    Please find attached a pdf file of a Critique of Blockchain/Bitcoin for those who may be interested in taking a critical look at the technical merits and deficiencies of Blockchain/Bitcoin. I hope this can help spur healthy technical discussions about this topic. There is no restriction on redistribution of this material. Feel free to distribute. BitcoinCritique.pdf

  6. Started by Prometheus,

    Can someone give me sanity check. I've been doing PCA in matlab and python with sklearn and been getting slightly different results. Here's a toy dataset to illustrate: In Matlab: ty = -1.383405780000000 0.293578700000000 -2.221898020000000 -0.251334840000000 3.605303800000000 0.042243850000000 1.383405780000000 -0.293578700000000 2.221898020000000 0.251334840000000 3.605303800000000 -0.042243850000000 [~, ty_sc] = pca(ty) ty_sc = -2.5821 0.3192 -3.4260 -0.2174 2.4038 0.0184 0.1787 -0.2954 1.0226 0.2412 2.4030 -0.0661 In python with sklearn: from sklearn import decomposition ty = np.array([(…

    • 0

      Reputation Points

    • 0 replies
    • 2.4k views
  7. Started by zak100,

    Hi, I am trying to understand the following python code: from collections import defaultdict j1 = 5 j2 = 3 # aim = int(input("Enter the capacity of goal litters : ")) # the already visited node is to stored to save time and memory. visited = defaultdict(lambda: False) def waterJugSolver(amt1, amt2): if (amt1 == 1 and amt2 == 0): print(amt1, amt2) return True if visited[(amt1, amt2)] == False: print(amt1, amt2) visited[(amt1, amt2)] = True if (waterJugSolver(0, amt2)): exit(1) if (waterJugSolver(amt1, 0)): exit(1) if (waterJugSolver(j1, amt2)): exit(1) …

    • 0

      Reputation Points

    • 4 replies
    • 2k views
  8. Hi, I can't understand the path specified in red arcs in the attached slide. The slide shows a movement from A to C and then from C to B and then from B to D. I can’t understand the C to B and B to D movements (or arcs) because there is no edge supporting these movements. Somebody please explain me the path shown in the red dotted line in the slide.

    • 0

      Reputation Points

    • 2 replies
    • 1.6k views
  9. Started by fiveworlds,

    I have a HDTV for a few years but now my tv box isn't working and I get an error about not having HDCP? Does anyone know about this?

    • 0

      Reputation Points

    • 2 replies
    • 919 views
  10. Started by nae,

    Hi everyone! The reason I am here now is cause I want to know what computer science really involves? Like what would I do if I were to go to University for the degree? I recently became much more curious in this field cause I want to make sure I won't make a mistake in choosing it. That's all! Thanks!

    • 0

      Reputation Points

    • 1 reply
    • 833 views
  11. Hi, I am trying to run th efollowing program, I got it from :Tree with Multiple children from anytree import Node, RenderTree udo = Node("Udo") marc = Node("Marc", parent=udo) lian = Node("Lian", parent=marc) dan = Node("Dan", parent=udo) jet = Node("Jet", parent=dan) jan = Node("Jan", parent=dan) joe = Node("Joe", parent=dan) I am getting th efollowing error: File "PycharmProjects/AIHW/venv/TreeDS.py", line 1, in <module> from anytree import Node, RenderTree ModuleNotFoundError: No module named 'anytree' Somebody please guide me. Zulfi.

    • 0

      Reputation Points

    • 4 replies
    • 2k views
  12. Hi, I can't understand the code, is it creating five lambda function definition with in the list, I have got the following code; print("list3") fun_list3 = [lambda e: e+i for i in range(5)] #The lambda function returns e+i for i in range(5), Note e is the argument of lambda function print([f(10) for f in fun_list3]) The output is: I can’t understand the output of the function, its printing: From print statement we are passing 10 to the lambda function argument, lambda function evaluates “e+i” so its output is 10 first time, and second time, it should be 11, and 3rd time 12 and so on, but I can’t understand this output. …

    • 0

      Reputation Points

    • 3 replies
    • 1k views
  13. Started by ZeroZero,

    Hi. I am trying to understand qbits. I have general knowledge of quantum theory. In a ordinary silicon chip a transistor can be set to either 0 or 1 and therefore can store one bit of information that can be read. I understand that a quibit can be in three states. If it is not being read it is in a state which can either be a 0 or a 1. If it is not being read, it in a state which is described as both a 0and a 1 at the same time, a quantum state. Let’s say one wants to store a bit of information in it, example a1. How does one do this? If later we need to retrieve this information, when we retrieve this information, then we must read the information from the qbit, how do…

    • 0

      Reputation Points

    • 0 replies
    • 770 views
    • 1 follower
  14. Hi, I got some in complet program from a book "aipython": The code after some modification is: fun_list1 = [ ] for j in range(5): def fun1(e): return e + j fun_list1.append(fun1) for x in fun_list1: print(x) What I understand is that I have a for loop which is invokingthe function "fun1(e)" 5 times and the return value is stored in a list.I trying to print the list, I am getting following output: So I understand that I have to put this whole thing in a function and then pass some argument e to the function, and then it will work. Some body please guide how to execute this program such that I get some answer for the list…

    • 0

      Reputation Points

    • 3 replies
    • 976 views
    • 1 follower
  15. Hi, Following is the program similar to : Storing the function in the list fun_list2 = [ ] for i in range(5): def fun2(e, iv=i): return e + iv fun_list2.append(fun2) print([f(10) for f in fun_list2]) From the above link, I am able to understand the above code. However, I have problem in understanding the '[....]' in the print statement. If I run the above program without square brackets like: print(f(10) for f in fun_list2) I am getting the message: Somebody please guide me. Zulfi.

    • 0

      Reputation Points

    • 1 reply
    • 819 views
  16. Hi, I am trying to understand the Water Jug Problem. It can be represented by a tree but I can't understand that representation. I have following questions about thee tree: 1. How we created the left and right part of the tree? 2. What is the number on the edges indicates? Zulfi.

    • 0

      Reputation Points

    • 0 replies
    • 862 views
  17. import numpy as np import pandas as pd df3 = pd.DataFrame([[0, 2, 3], [0, 4, 1], [10, 20, 30]], index=[4, 5, 6], columns=['A', 'B', 'C']) print(df3) df3.at[4, 'B'] Following is the output: Somebody please guide me, how can i print the value of last statement? I solved this problem: print(df3.at[4, 'B']) Zulfi.

    • 0

      Reputation Points

    • 0 replies
    • 649 views
  18. Started by zak100,

    Hi, I am trying to execute the following code: df2 = pd.DataFrame(np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]), columns=['a', 'b', 'c']) df2 = pd.DataFrame(data=d, dtype=np.int8) print(df2) I am getting the following error message: Somebody please guide me. Zulfi.

    • 0

      Reputation Points

    • 2 replies
    • 980 views
  19. Hi, I am following the link at: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.html The link says that Constructing DataFrame from a dictionary and then it shows the program: import pandas as pd d={'col1': [1, 2], 'col2':[3, 4]} df = pd.DataFrame(data = d) print (df) I got the following output: I can't understand the concept of dictionary here. Somebody please guide me with a more meaningful example. Zulfi.

    • 0

      Reputation Points

    • 3 replies
    • 1k views
  20. I am trying to understand the pandas package. I understand that it is 2d representation of data. I got the following program from the link: http://www.python-ds.com/python-pandas import pandas as pd prices=[ [71,72,73],[77,78,70],[79,72,73], [74,78,70],[71,88,73],[77,68,70], [71,72,73],[77,78,70],[79,72,73], [74,78,70],[71,88,73],[77,68,70] ] simple_dataframe=pd.DataFrame(prices) I can understand the above code. But I am having problem in understanding the following line: print("Simple Data Frame\n",simple_dataframe) header_dataframe=pd.DataFrame(prices,columns=['Jan','Feb','Mar']) I can’t understand the command pd.DataFr…

    • 0

      Reputation Points

    • 1 reply
    • 768 views
  21. Started by zak100,

    Hi, I am trying to compile the following program: import numpy as np import sklearn.preprocessing from sklearn import preprocessing Input_data = np.array([2.1, -1.9, 5.5], [-1.5, 2.4, 3.5], [0.5, -7.9, 5.6], [5.9, 2.3, -5.8]) data_binarized = preprocessing.Binarizer(threshold = 0.5). transform(Input_data) print("\nBinarized data:\n", data_binarized) I am getting the following error: Traceback (most recent call last): File "/home/zulfi/PycharmProjects/AI/AI1.py", line 8, in <module> [5.9, 2.3, -5.8]) TypeError: array() takes from 1 to 2 posit…

    • 0

      Reputation Points

    • 2 replies
    • 1k views
  22. Started by Coletrane315,

    Hey everyone, I'm brand new to posting to forums, but it seems appropriate for a project I am working on. For those of you who don't know what the Schelling Model is, I will give a brief explanation. In the 1960s, a man named Thomas Schelling developed a model to predict how people would move to a new house based on having neighbors of different race, ethnicity, or socioeconomic status. In the case of my program, I have a grid of squares, I'll use 8x8 as an example. There are 23 black circles and 24 red circles that are randomly placed in a square. Then a random circle is selected, if there are a certain amount (usually 1) of differently colored circles in the 8 squares…

    • 0

      Reputation Points

    • 1 reply
    • 1k views
  23. Started by Waliiid,

    Hi guys , how are you doing , wish you are all doing great . I am waleed and i am new here and i would like to ask a question , what are the most strong and necessary languages to learn in order to be a programmer , and how to think as an information and acquire the method of thinking of an information ? Thank you all !

    • 0

      Reputation Points

    • 5 replies
    • 1.2k views
    • 1 follower
  24. Hi, I'm new to the forum and just seeking advice with programming in general. I've studied computer science for one year and I don't feel I understand enough about coding/programming. I'm really concerned about this as I have a programming assignment that's due the start of August and I've made very little progress with it. The other modules that don't involve as much coding and programming I've been absolutely fine with. It's just the programming assignments. I cannot build programs, I really don't know why. My brain just cannot understand it and as a computer science student, that's a massive problem. Can anybody please help? Thank you.

    • 0

      Reputation Points

    • 6 replies
    • 1.9k views
  25. Can i talk to someone privately about computer hardware and software? Someone who knows about building things like rasberry pi. I need some help with something. Email me @ suad176@gmail.com. its about creating a new device.

    • 0

      Reputation Points

    • 1 reply
    • 795 views

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.