 1551103728

# Numpy python R eqivalent indexing

```import numpy as np

o = np.array([

[
[1,2,3,4],
[5,6,7,8]
],

[
[9,10,11,12],
[13,14,15,16]
]

])
print(o.flatten())

# array([ 1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16])
```

It first flattens the row of each matrix

But I want that it flattens the coluumn of each matrix first so that it prints [1,5,2,6,3,7,4,8,9,13,10,14,11,15,12,16]

I tried searching and what I found was passing "F" as an argument but that gives [1,5,9,13,2,6,10,14,3,7,11,15,4,8,12,16] that is it switches to another matrix without completing first.

In short, I would like to find python equivalent of R's indexing with double brackets

```someData <- rep(0, 2*3*4);
ar <- array(someData, c(2, 3, 4));
ar[1,1,1] = 1
ar[1,2,1] = 2
ar[1,3,1] = 3
ar[2,1,1] = 4
ar[2,2,1] = 5
ar[2,3,1] = 6
ar[1,1,2] = 7
ar[1,2,2] = 8
ar[1,3,2] = 9
print(ar[]) # 1
print(ar[]) # 4
print(ar[]) # 2
print(ar[]) # 5
print(ar[]) # 3
print(ar[]) # 6
```

#python #numpy #data-science #r

## Buddha Community 1551146200

3

You can start by doing a `[np.concatenate](https://docs.scipy.org/doc/numpy-1.14.0/reference/generated/numpy.concatenate.html "np.concatenate")` on the second dimension, and then `[flatten](https://docs.scipy.org/doc/numpy-1.15.0/reference/generated/numpy.ndarray.flatten.html "flatten")` in column-major order as you also mentioned:

``````np.concatenate(o, axis=1).flatten(order='f')

``````

Output

``````array([ 1,  5,  2,  6,  3,  7,  4,  8,  9, 13, 10, 14, 11, 15, 12, 16])

`````` 1619518440

## top 30 Python Tips and Tricks for Beginners

Welcome to my Blog , In this article, you are going to learn the top 10 python tips and tricks.

### 8) Check The Memory Usage Of An Object.

#python #python hacks tricks #python learning tips #python programming tricks #python tips #python tips and tricks #python tips and tricks advanced #python tips and tricks for beginners #python tips tricks and techniques #python tutorial #tips and tricks in python #tips to learn python #top 30 python tips and tricks for beginners 1619510796

## Lambda, Map, Filter functions in python

Welcome to my Blog, In this article, we will learn python lambda function, Map function, and filter function.

Lambda function in python: Lambda is a one line anonymous function and lambda takes any number of arguments but can only have one expression and python lambda syntax is

Syntax: x = lambda arguments : expression

Now i will show you some python lambda function examples:

#python #anonymous function python #filter function in python #lambda #lambda python 3 #map python #python filter #python filter lambda #python lambda #python lambda examples #python map 1624422360

## R vs Python: What Should Beginners Learn?

### Let go of any doubts or confusion, make the right choice and then focus and thrive as a data scientist.

I currently lead a research group with data scientists who use both R and Python. I have been in this field for over 14 years. I have witnessed the growth of both languages over the years and there is now a thriving community behind both.

I did not have a straightforward journey and learned many things the hard way. However, you can avoid making the mistakes I made and lead a more focussed, more rewarding journey and reach your goals quicker than others.

Before I dive in, let’s get something out of the way. R and Python are just tools to do the same thing. Data Science. Neither of the tools is inherently better than the other. Both the tools have been evolving over years (and will likely continue to do so).

Therefore, the short answer on whether you should learn Python or R is: it depends.

The longer answer, if you can spare a few minutes, will help you focus on what really matters and avoid the most common mistakes most enthusiastic beginners aspiring to become expert data scientists make.

#r-programming #python #perspective #r vs python: what should beginners learn? #r vs python #r 1551103728

## Numpy python R eqivalent indexing

```import numpy as np

o = np.array([

[
[1,2,3,4],
[5,6,7,8]
],

[
[9,10,11,12],
[13,14,15,16]
]

])
print(o.flatten())

# array([ 1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16])
```

It first flattens the row of each matrix

But I want that it flattens the coluumn of each matrix first so that it prints [1,5,2,6,3,7,4,8,9,13,10,14,11,15,12,16]

I tried searching and what I found was passing "F" as an argument but that gives [1,5,9,13,2,6,10,14,3,7,11,15,4,8,12,16] that is it switches to another matrix without completing first.

In short, I would like to find python equivalent of R's indexing with double brackets

```someData <- rep(0, 2*3*4);
ar <- array(someData, c(2, 3, 4));
ar[1,1,1] = 1
ar[1,2,1] = 2
ar[1,3,1] = 3
ar[2,1,1] = 4
ar[2,2,1] = 5
ar[2,3,1] = 6
ar[1,1,2] = 7
ar[1,2,2] = 8
ar[1,3,2] = 9
print(ar[]) # 1
print(ar[]) # 4
print(ar[]) # 2
print(ar[]) # 5
print(ar[]) # 3
print(ar[]) # 6
```

#python #numpy #data-science #r 1602968400

## Python Tricks Every Developer Should Know

Python is awesome, it’s one of the easiest languages with simple and intuitive syntax but wait, have you ever thought that there might ways to write your python code simpler?

In this tutorial, you’re going to learn a variety of Python tricks that you can use to write your Python code in a more readable and efficient way like a pro.

### Let’s get started

Swapping value in Python

Instead of creating a temporary variable to hold the value of the one while swapping, you can do this instead

``````>>> FirstName = "kalebu"
>>> LastName = "Jordan"
>>> FirstName, LastName = LastName, FirstName
>>> print(FirstName, LastName)
('Jordan', 'kalebu')
``````

#python #python-programming #python3 #python-tutorials #learn-python #python-tips #python-skills #python-development