Combining two array in python with np [closed] - python

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
I have two array one with shape (320,1) and one with (850,1) how should I combine the two array. I tried np.append however it seems to be an error.

Assuming the two arrays are called arr1 and arr2, you could try the following code:
arr3 = np.append(arr1,arr2).reshape((-1,1))
The reshape is needed to make sure the final shape is (1170,1) instead of (1170,)

Related

Converting H/T to 0/1 binary array [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed last year.
Improve this question
I’ve loaded a sample using the code:
Data = np.load(sample_1.npy)
I need to convert the data points from H/T (coin tosses) to 0/1 (binary array). Not sure what code would work for this? I’ve tried googling answers and they haven’t worked.
If it's an array with "H" and "T" as values, you could try that:
Data = np.array([0 if x == "H" else 1 for x in Data])

Element wise multiplication using Numpy [Python] [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
I'm trying to get the element-wise mulitplication using normal *, and i tried np.multiply(), both give a weird answers.
now (1-y) is (100,) and np.log(1-sigmoid(np.dot(X,theta)))) is (100,1), so when i muliply them by element-wise, it should give (100,1); but it gives me (100,100) matrix(ALL are higlighted BLUE)
Here is my original function if it can help.
Can anyone help me with getting the source of erre here?
I'm not 100% sure why python does this, but the way to solve it would be to apply np.reshape((1-y),(100,1)) and then apply np.multiply(). In general it's always better to reshape your arrays and to give them a second dimension.
EDIT: This explains how numpy does the broadcasting when using an array of dimensions (n,) and (n,1).

how to cast certain key values to floats using python [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
Given this dictionary:
my_dict={'animal':['Dog','Cat'],'age':[4,5],'bark':[True,False],'badge_num':['234','896']}
what code will cast 'age' to float?
you could use map combined with float like the following:
my_dict['age']=list(map(float, my_dict['age']))

How to convert list to integer [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
When I run
print(c)
I get the output
[45]
How do I remove the [ ] and get output like this as an integer?
45
Because I want to print this but It won't run.
print(b[c:c+50])
Take the first element of that array.
print(c[0])

Arrays being re-assigned (Python) [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I'm recreating Conway's game of life in pygame, and I've been having an issue implementing the preset feature. When I'm assigning the preset array to the default array, and then assigning it back to the default array again, the preset is changed. I'm only editing the array "Initial_frame" but it is somehow changing the preset array.
Code:
https://paste.pythondiscord.com/uvetekikot.py
You are probably doing something like this:
a = [1 2 3 4 5]
b = a
a and b are really arrays, rather they are references to arrays. b=a means they both reference the same array.
You will need to copy the array instead of just copying the reference, like this:
b = a[:]

Categories

Resources