array-broadcasting Questions
1
Solved
I have quite a simple scenario where I'd like to test whether both elements of a two-dimensional array are (separately) members of a larger array - for example:
full_array = np.array(['A','B','C',...
Keniakenilworth asked 5/12, 2018 at 11:39
2
I have this DataFrame like this:
1 2 1 3 1 4
2 4 5 1 1 4
1 3 5 3 1 4
1 3 1 3 1 4
Another like this
1 1 0 0 0 0
I want to multiply them such as that I get
1 2 0 0 0 0
2 4 0 0 0 0
1 3 0 0 0 0
...
Highkey asked 12/10, 2018 at 2:4
3
Solved
Let's say I have an array like this:
import numpy as np
base_array = np.array([-13, -9, -11, -3, -3, -4, 2, 2,
2, 5, 7, 7, 8, 7, 12, 11])
Suppose I want to know: "how many elements in base_arr...
Superficies asked 6/8, 2018 at 16:3
2
Solved
I have an ndarray of N 1x3 arrays I'd like to perform dot multiplication with a 3x3 matrix. I can't seem to figure out an efficient way to do this, as all the multi_dot and tensordot, etc methods s...
Mouthwatering asked 26/7, 2018 at 5:12
1
Solved
Related to this question, I came across an indexing behaviour via Boolean arrays and broadcasting I do not understand. We know it's possible to index a NumPy array in 2 dimensions using integer ind...
Seel asked 4/7, 2018 at 16:26
2
Solved
Assuming I want have a numpy array of size (n,m) where n is very large, but with a lot of duplication, ie. 0:n1 are identical, n1:n2 are identical etc. (with n2%n1!=0, ie not regular intervals). Is...
Disproportion asked 1/6, 2018 at 7:47
1
Solved
The arrays are of following dimensions:
dists: (500,5000)
train: (5000,)
test:(500,)
Why does the first two statements throw an error whereas the third one works fine?
dists += train + test
Er...
Admiralty asked 8/6, 2018 at 10:3
1
I start with a 2D array and want to broadcast it to a 3D array (eg. from greyscale image to rgb image). This is the code I use.
>>> img_grey = np.random.randn(4, 4)
>>> img_rgb =...
Tiga asked 5/4, 2018 at 13:38
2
Solved
index = np.array([[1,2],[2,4],[1,5],[5,6]])
z = np.zeros(shape = [4,10], dtype = np.float32)
What is the efficient way to set z[np.arange(4),index[:,0]], z[np.arange(4), index[:,1]] and everythin...
Cypher asked 9/3, 2018 at 6:54
4
Solved
In the following code I have written 2 methods that theoretically(in my mind) should do the same thing. Unfortunately they don't, I am unable to find out why they don't do the same thing per the nu...
Neutrality asked 27/2, 2018 at 15:18
2
Solved
On a numpy array, why is it I can successfully use / 2:
>>> a=np.array([2, 4, 6])
>>> a = a / 2
>>> a
array([ 1., 2., 3.])
But I cannot use a /= 2?
>>> a=np....
Lykins asked 23/2, 2018 at 12:48
2
Solved
I have a numpy array with shape (34799, 32, 32, 3)which means (num examples, width, height, channels).
Now I normalize the image data with the following code:
def normalize(x):
return (x - 128) ...
Rife asked 14/2, 2018 at 10:40
2
Solved
Given two arrays, A (shape: M X C) and B (shape: N X C), is there a way to subtract each row of A from each row of B without using loops? The final output would be of shape (M N X C).
Example
A = ...
Murton asked 20/1, 2018 at 17:27
3
Solved
This question is a follow up to my answer in
Efficient way to compute the Vandermonde matrix.
Here's the setup:
x = np.arange(5000) # an integer array
N = 4
Now, I'll compute the Vandermond...
Carotid asked 14/1, 2018 at 19:11
4
Solved
I am new to Python and I need to implement a clustering algorithm. For that, I will need to calculate distances between the given input data.
Consider the following input data -
[[1,2,8],
[7,4...
Agglomeration asked 12/10, 2017 at 2:11
3
Solved
I have an ndarray, and I want to replace every value in the array with the mean of its adjacent elements. The code below can do the job, but it is super slow when I have 700 arrays all with shape (...
Genova asked 6/7, 2016 at 19:44
1
Solved
Answering this question, some others and I were actually wrong by considering that the following would work:
Say one has
test = [ [ [0], 1 ],
[ [1], 1 ]
]
import numpy as np
nptest = np.array(t...
Moray asked 31/7, 2017 at 23:7
2
Solved
This question is close to what is asked in Overriding other __rmul__ with your class's __mul__ but I am under the impression that this is a more general problem then only numerical data. Also t...
Lamblike asked 19/11, 2016 at 15:8
1
Solved
So here's the deal: I have variable x which is a numpy.ndarray. The size of this structure is 1000. If I do x[0], then I get a numpy.void, of 4 numbers. If I do x[1], then I get another numpy.void,...
Polytrophic asked 31/5, 2017 at 22:3
2
Solved
Consider the array a
np.random.seed([3,1415])
a = np.random.randint(10, size=(5, 4))
a
array([[0, 2, 7, 3],
[8, 7, 0, 6],
[8, 6, 0, 2],
[0, 4, 9, 7],
[3, 2, 4, 3]])
I can create b which con...
Stitching asked 25/5, 2017 at 22:16
1
Solved
I try to store a list of different shaped arrays as a dtype=object array using np.save (I'm aware I could just pickle the list but I'm really curious how to do this).
If I do this:
import numpy as...
Infinitive asked 2/4, 2017 at 21:6
4
Solved
I'm trying to find some way to substract a size 3 vector from each column of a 3*(a big number) matrix in Matlab. Of course I could use a loop, but I'm trying to find some more efficient solution, ...
Redletter asked 9/7, 2010 at 13:49
2
Solved
Is there any difference between numpy.add(a,b) and a+b when adding two ndarrays a and b?
The documentation says that numpy.add is the "Equivalent to x1 + x2 in terms of array broadcasting.".
But I ...
Receptor asked 3/8, 2016 at 15:19
1
Solved
There must be some 'pythonic' way to do this, but I don't think np.place, np.insert, or np.put are what I'm looking for. I want to replace the values inside of a large 3D array A with those of a sm...
Menace asked 8/10, 2015 at 2:2
4
I'm trying to understand why numpy's dot function behaves as it does:
M = np.ones((9, 9))
V1 = np.ones((9,))
V2 = np.ones((9, 5))
V3 = np.ones((2, 9, 5))
V4 = np.ones((3, 2, 9, 5))
Now np.dot(M,...
Shanitashank asked 29/11, 2015 at 11:39
© 2022 - 2024 — McMap. All rights reserved.