numpy

Producing 2D perlin noise with numpy

坚强是说给别人听的谎言 提交于 2021-02-07 05:19:55
问题 I'm trying to produce 2D perlin noise using numpy, but instead of something smooth I get this : my broken perlin noise, with ugly squares everywhere For sure, I'm mixing up my dimensions somewhere, probably when I combine the four gradients ... But I can't find it and my brain is melting right now. Anyone can help me pinpoint the problem ? Anyway, here is the code: %matplotlib inline import numpy as np import matplotlib.pyplot as plt def perlin(x,y,seed=0): # permutation table np.random.seed

Producing 2D perlin noise with numpy

对着背影说爱祢 提交于 2021-02-07 05:19:47
问题 I'm trying to produce 2D perlin noise using numpy, but instead of something smooth I get this : my broken perlin noise, with ugly squares everywhere For sure, I'm mixing up my dimensions somewhere, probably when I combine the four gradients ... But I can't find it and my brain is melting right now. Anyone can help me pinpoint the problem ? Anyway, here is the code: %matplotlib inline import numpy as np import matplotlib.pyplot as plt def perlin(x,y,seed=0): # permutation table np.random.seed

NumPy types with underscore: `int_`, `float_`, etc

自闭症网瘾萝莉.ら 提交于 2021-02-07 05:01:13
问题 What is the significance of the underscore suffixing in int_ , float_ , etc.? 回答1: From page 21 of Guide to Numpy by TE Oliphant: Names for the data types that would clash with standard Python object names are followed by a trailing underscore, ’ ’. These data types are so named because they use the same underlying precision as the corresponding Python data types. . . . The array types bool_ , int_ , complex_ , float_ , object_ , unicode_ , and str_ are enhanced-scalars. They are very similar

slicing numpy array in periodic conditions

感情迁移 提交于 2021-02-07 04:27:10
问题 how can I slice a 3x3 shape numpy array in periodic conditions. for example, for simplicity its in one dimension: import numpy as np a = np.array(range(10)) if the slice is within the length of the array it is straightforward sub = a[2:8] the result is array([2, 3, 4, 5, 6, 7]) . Now if I need to slice from 7 to 5 ... sub = a[7:5] the result is obviously array([], dtype=int32) . But what I need is array([7,8,9,0,1,2,3,4]) Is there any efficient way to do so ? 回答1: I think what you're looking

Numpy: given the nonzero indices of a matrix how to extract the elements into a submatrix

若如初见. 提交于 2021-02-07 04:26:47
问题 I have very sparse matrices, so I want to extract the smallest rectangular region of a matrix that has non-zero values. I know that numpy.nonzero(a) gives you the indices of the elements that are non-zero, but how can I use this to extract a submatrix that contains the elements of the matrix at those indices. To give an example, this is what I am aiming for: >>> test array([[0, 0, 0, 0, 0, 0], [0, 1, 1, 1, 1, 0], [0, 0, 1, 1, 0, 0]]) >>> np.nonzero(test) (array([1, 1, 1, 1, 2, 2]), array([1,

Efficient implementation of pairwise distances computation between observations for mixed numeric and categorical data

送分小仙女□ 提交于 2021-02-07 04:07:15
问题 I am working on a data science project in which I have to compute the euclidian distance between every pair of observations in a dataset. Since I am working with very large datasets, I have to use an efficient implementation of pairwise distances computation (both in terms of memory usage and computation time). One solution is to use the pdist function from Scipy, which returns the result in a 1D array, without duplicate instances. However, this function is not able to deal with categorical

Efficient implementation of pairwise distances computation between observations for mixed numeric and categorical data

和自甴很熟 提交于 2021-02-07 04:02:09
问题 I am working on a data science project in which I have to compute the euclidian distance between every pair of observations in a dataset. Since I am working with very large datasets, I have to use an efficient implementation of pairwise distances computation (both in terms of memory usage and computation time). One solution is to use the pdist function from Scipy, which returns the result in a 1D array, without duplicate instances. However, this function is not able to deal with categorical

Find consecutive ones in numpy array

夙愿已清 提交于 2021-02-07 03:51:33
问题 How can I find the amount of consecutive 1 (or any other value) in each row for of the following numpy array. I need a pure numpy solution. counts Out[304]: array([[0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0], [0, 0, 1, 0, 0, 1, 2, 0, 0, 1, 1, 1], [0, 0, 0, 4, 1, 0, 0, 0, 0, 1, 1, 0]]) desired solution first question (what is the maximum number of 1 in a row): amount: array([2,3,2]) second question (the index of where there are 2x a 1 in a row: index: array([3,9,9]) In this example I put 2x in a row.

Find consecutive ones in numpy array

徘徊边缘 提交于 2021-02-07 03:48:46
问题 How can I find the amount of consecutive 1 (or any other value) in each row for of the following numpy array. I need a pure numpy solution. counts Out[304]: array([[0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0], [0, 0, 1, 0, 0, 1, 2, 0, 0, 1, 1, 1], [0, 0, 0, 4, 1, 0, 0, 0, 0, 1, 1, 0]]) desired solution first question (what is the maximum number of 1 in a row): amount: array([2,3,2]) second question (the index of where there are 2x a 1 in a row: index: array([3,9,9]) In this example I put 2x in a row.

Find consecutive ones in numpy array

半腔热情 提交于 2021-02-07 03:46:42
问题 How can I find the amount of consecutive 1 (or any other value) in each row for of the following numpy array. I need a pure numpy solution. counts Out[304]: array([[0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0], [0, 0, 1, 0, 0, 1, 2, 0, 0, 1, 1, 1], [0, 0, 0, 4, 1, 0, 0, 0, 0, 1, 1, 0]]) desired solution first question (what is the maximum number of 1 in a row): amount: array([2,3,2]) second question (the index of where there are 2x a 1 in a row: index: array([3,9,9]) In this example I put 2x in a row.